This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
chore(typescript): Add better TypeScript definitions for Angular #116
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fbfd759
Remove array check on scopes (#120)
jmelberg-okta 0f3d071
Requesting tokens returns their string value (#115)
jmelberg-okta 2934fc9
chore(typescript): Add better TypeScript definitions for Angular
cmckni3 c2117e1
chore(banner): Add banner file
cmckni3 cc36193
fix(demo): Fix demo and test harness
cmckni3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/okta-angular/src/okta/models/auth-required-function.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2017, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { Router } from '@angular/router'; | ||
|
||
import { OktaAuthService } from '../services/okta.service'; | ||
|
||
export type AuthRequiredFunction = (oktaAuth: OktaAuthService, router: Router) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,10 @@ | |
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { Inject, Injectable, Optional } from '@angular/core'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
|
||
import { OKTA_CONFIG } from './okta.config'; | ||
import { OKTA_CONFIG, OktaConfig } from '../models/okta.config'; | ||
|
||
/** | ||
* Import the okta-auth-js library | ||
|
@@ -22,11 +22,11 @@ import * as OktaAuth from '@okta/okta-auth-js'; | |
|
||
@Injectable() | ||
export class OktaAuthService { | ||
private oktaAuth; | ||
private config; | ||
private oktaAuth: OktaAuth; | ||
private config: OktaConfig; | ||
|
||
constructor(@Inject(OKTA_CONFIG) private auth, private router: Router) { | ||
const missing: any[] = []; | ||
constructor(@Inject(OKTA_CONFIG) private auth: OktaConfig, private router: Router) { | ||
const missing: string[] = []; | ||
|
||
if (!auth.issuer) { | ||
missing.push('issuer'); | ||
|
@@ -63,35 +63,37 @@ export class OktaAuthService { | |
/** | ||
* Returns the OktaAuth object to handle flows outside of this lib. | ||
*/ | ||
getOktaAuth() { | ||
getOktaAuth(): OktaAuth { | ||
return this.oktaAuth; | ||
} | ||
|
||
/** | ||
* Checks if there is a current accessToken in the TokenManager. | ||
*/ | ||
isAuthenticated() { | ||
isAuthenticated(): boolean { | ||
return !!this.oktaAuth.tokenManager.get('accessToken'); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the type definitions of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like #115 corrects it. |
||
/** | ||
* Returns the current accessToken in the tokenManager. | ||
*/ | ||
getAccessToken() { | ||
return this.oktaAuth.tokenManager.get('accessToken'); | ||
async getAccessToken(): Promise<string | undefined> { | ||
const accessToken = this.oktaAuth.tokenManager.get('accessToken'); | ||
return accessToken ? accessToken.accessToken : undefined; | ||
} | ||
|
||
/** | ||
* Returns the current idToken in the tokenManager. | ||
*/ | ||
getIdToken() { | ||
return this.oktaAuth.tokenManager.get('idToken'); | ||
async getIdToken(): Promise<string | undefined> { | ||
const idToken = this.oktaAuth.tokenManager.get('idToken'); | ||
return idToken ? idToken.idToken : undefined; | ||
} | ||
|
||
/** | ||
* Returns the configuration object used. | ||
*/ | ||
getOktaConfig(){ | ||
getOktaConfig(): OktaConfig { | ||
return this.config; | ||
} | ||
|
||
|
@@ -109,16 +111,16 @@ export class OktaAuthService { | |
|
||
/** | ||
* Stores the intended path to redirect after successful login. | ||
* @param uri | ||
* @param uri | ||
*/ | ||
setFromUri(uri) { | ||
setFromUri(uri: string) { | ||
localStorage.setItem('referrerPath', uri); | ||
} | ||
|
||
/** | ||
* Returns the referrer path from localStorage or app root. | ||
*/ | ||
getFromUri() { | ||
getFromUri(): string { | ||
const path = localStorage.getItem('referrerPath') || '/'; | ||
localStorage.removeItem('referrerPath'); | ||
return path; | ||
|
@@ -127,7 +129,7 @@ export class OktaAuthService { | |
/** | ||
* Parses the tokens from the callback URL. | ||
*/ | ||
async handleAuthentication() { | ||
async handleAuthentication(): Promise<void> { | ||
const tokens = await this.oktaAuth.token.parseFromUrl(); | ||
tokens.forEach(token => { | ||
if (token.idToken) { | ||
|
@@ -148,20 +150,18 @@ export class OktaAuthService { | |
* Clears the user session in Okta and removes | ||
* tokens stored in the tokenManager. | ||
*/ | ||
async logout() { | ||
async logout(): Promise<void> { | ||
this.oktaAuth.tokenManager.clear(); | ||
await this.oktaAuth.signOut(); | ||
} | ||
|
||
/** | ||
* Scrub scopes to ensure 'openid' is included | ||
* @param scopes | ||
*/ | ||
scrubScopes(scopes) { | ||
scrubScopes(scopes: string): string { | ||
if (!scopes) { | ||
return 'openid email'; | ||
} else { | ||
// Make sure object is a string | ||
scopes = Array.isArray(scopes) ? scopes.join(' ') : scopes | ||
} | ||
if (scopes.indexOf('openid') === -1) { | ||
return scopes + ' openid'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the license banner to this file? An example is available here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done