Apache + Angular Oauth redirection : Resource not found

百般思念 提交于 2019-12-25 00:25:35

问题


Morning;

I am trying to deploy my angular project under apache and I encountered some problems with redirection in Angular.

The user try to authenticate in my App using Oauth2. So it will be redirect to another domain to make authentication and then the other domain redirect the user to my application with an access token. The problem when making redirection, it shows up “resource not found”, so I tried to find a solution and I found those two solution:

I insert the “{usehash : true}” in RootModule.forRoot() but it did not works

/ 20180103143205
// http://radouani-**********?username=*****&scope=token%20openid%20profile&client_id=***&redirect_uri=http%3A%****en&response_type=token

{
  "ErrorCode": "invalid_request",
  "Error": "Invalid redirection uri http://******/#/authentication/token"
}

I add this configuration under apache

Apache Config :

<VirtualHost *:80>
    ServerName www.ofi-demo.com
    ServerAlias ofi-demo.com
    DocumentRoot /var/www/demo/public_html

    <Directory /var/www/demo/public_html>
        RewriteEngine on

        # Don't rewrite files or directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]

        # Rewrite everything else to index.html to allow HTML5 state links
        RewriteRule ^ index.html [L]
    </Directory>
</VirtualHost>

but I got this problem “"Uncaught SyntaxError: Unexpected token <" . I looked in the network tab under chrome and I found that apache (I think) insert those line in js file

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>OFI-Asset Management API DEMO</title><base href="./"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" rel="stylesheet"><link href="assets/fonts/feather/style.min.css" rel="stylesheet"><link href="assets/fonts/simple-line-icons/style.css" rel="stylesheet"><link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700,900|Montserrat:300,400,500,600,700,800,900" rel="stylesheet" type="text/css"><link rel="stylesheet" href="assets/vendor/pace/themes/black/pace-theme-flash.css"/><style type="text/css">.pace .pace-activity {
      top: 19px;
……
}

So what configuration I need to make the redirection works in Angular?


回答1:


Thanks I add this configuration in .htaccess file (in the same directory where the index.html resides) and it works; Thanks

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>


来源:https://stackoverflow.com/questions/48076301/apache-angular-oauth-redirection-resource-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!