Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kdhttps/auth0-angular-node
Auth0 authentication with Angular and NodeJS :rocket:
https://github.com/kdhttps/auth0-angular-node
angular7 auth0 auth0-jwt authentication nodejs openid-connect
Last synced: 29 days ago
JSON representation
Auth0 authentication with Angular and NodeJS :rocket:
- Host: GitHub
- URL: https://github.com/kdhttps/auth0-angular-node
- Owner: kdhttps
- License: mit
- Created: 2019-03-21T19:03:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T16:47:50.000Z (almost 2 years ago)
- Last Synced: 2023-03-03T16:13:56.673Z (almost 2 years ago)
- Topics: angular7, auth0, auth0-jwt, authentication, nodejs, openid-connect
- Language: TypeScript
- Homepage:
- Size: 791 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Auth0 Authentication
> Note: Not official support, Just love to contribute ;-)
Authentication with OAuth0 in Angular and NodeJS.
Below is the solution for to get Access Token as JWT and JWT verification with NodeJS.
## JWT Access Token
1. Need to use audience2. Configuration in angular app. All the keys are case sensitive. Use `environment.ts` file to store credentials.
```
auth0 = new auth0.WebAuth({
clientID: ',
domain: '',
responseType: 'token id_token',
audience: 'https:///api/v2/',
redirectUri: 'http://localhost:4200/callback',
logoutRedirect: 'http://localhost:4200',
scope: 'openid profile email'
});
```3. Auth0 Client Configuration
- Client settings
![client](docs/client.png)
- Audience URL
![audience](docs/audience.png)
### Notes
1. If you want access token as JWT then you must have to set audience.
2. Set APIs https:///api/v2/ in audience as given above example. Userinfo endpoint not working for me.
3. In the URL / is required at last. https:///api/v2/
4. Node side JWT verification
```
const authCheck = jwt({
secret: jwks.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: 'https:///.well-known/jwks.json'
}),
// This is the identifier we set when we created the API
audience: 'https:///api/v2/',
issuer: 'https:///',
algorithms: ['RS256']
});
```
5. In the URL / is required at last. https:///api/v2/ and https:///## Get Roles in Userinfo
1. Add roles and assign roles to users using auth0 dashboard.
2. Add rules in your auth0.
```
function (user, context, callback) {// Roles should only be set to verified users.
if (!user.email || !user.email_verified) {
return callback(null, user, context);
}user.app_metadata = user.app_metadata || {};
user.app_metadata.roles = context.authorization.roles;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
.then(function () {
context.idToken['https://example.com/roles'] = user.app_metadata.roles;
callback(null, user, context);
})
.catch(function (err) {
callback(err);
});
}
```