-
Notifications
You must be signed in to change notification settings - Fork 232
🌱 Make responseType configurable #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ export interface OktaConfig { | |
clientId?: string; | ||
scope?: string; | ||
onAuthRequired?: Function; | ||
responseType?: string; | ||
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. Should get some README love |
||
} | ||
|
||
export const OKTA_CONFIG = new InjectionToken<OktaConfig>('okta.config.angular'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { AppComponent } from './app.component'; | ||
import { environment } from './../environments/environment'; | ||
|
||
import { | ||
OktaAuthGuard, | ||
OktaAuthModule, | ||
OktaCallbackComponent, | ||
OktaLoginRedirectComponent | ||
} from '@okta/okta-angular'; | ||
|
||
describe('Unit Tests', () => { | ||
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. These spec files should be siblings of the source files, it's odd that we're burying unit testing within an e2e test. We should discuss this, we need to decide if we're going to fix this now or later. I also need a place to put unit testing for the user agent work 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. As discussed offline: this is going to be significant work and duplication of test boilerplate, so we won't do this. |
||
let component: AppComponent; | ||
let fixture: ComponentFixture<AppComponent>; | ||
|
||
beforeEach(() => { | ||
const config = { | ||
issuer: environment.ISSUER, | ||
redirectUri: environment.REDIRECT_URI, | ||
clientId: environment.CLIENT_ID, | ||
scope: 'email', | ||
responseType: 'id_token' | ||
}; | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule.withRoutes([{ path: 'foo', redirectTo: '/foo' }]), | ||
OktaAuthModule.initAuth(config) | ||
], | ||
declarations: [ | ||
AppComponent | ||
] | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AppComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create the app', async(() => { | ||
expect(component).toBeTruthy(); | ||
})); | ||
|
||
it('should instantiate the OktaAuth object', async(() => { | ||
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. We really should be testing that we correctly pass this down to the AuthJS constructor on the login redirect. To do so we would need to write a provider (or service?) wrapper around AuthJS so that it can easily be mocked via DI in test and observed. Out of scope for this PR, since we'll have to touch a lot of code with that change. |
||
const config = component.oktaAuth.getOktaConfig(); | ||
expect(config.issuer).toBe(environment.ISSUER); | ||
expect(config.redirectUri).toBe(environment.REDIRECT_URI); | ||
expect(config.clientId).toBe(environment.CLIENT_ID); | ||
expect(config.scope).toBe('email openid'); | ||
expect(config.responseType).toBe('id_token'); | ||
})); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,15 @@ import { | |
*/ | ||
import { ProtectedComponent } from './protected.component'; | ||
import { AppComponent } from './app.component'; | ||
import { SessionTokenLogin } from './sessionToken-login.component'; | ||
import { SessionTokenLoginComponent } from './sessionToken-login.component'; | ||
|
||
export function onNeedsAuthenticationGuard({ oktaAuth, router }) { | ||
router.navigate(['/sessionToken-login']); | ||
}; | ||
} | ||
|
||
export function onNeedsGlobalAuthenticationGuard({ oktaAuth, router }) { | ||
router.navigate(['/login']); | ||
}; | ||
} | ||
|
||
const appRoutes: Routes = [ | ||
{ | ||
|
@@ -48,7 +48,7 @@ const appRoutes: Routes = [ | |
}, | ||
{ | ||
path: 'sessionToken-login', | ||
component: SessionTokenLogin | ||
component: SessionTokenLoginComponent | ||
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. This looks like a breaking change? 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. This is used only in our test suite. We aren't exposing any of this via our SDK, so we aren't introducing a breaking change. |
||
}, | ||
{ | ||
path: 'implicit/callback', | ||
|
@@ -74,6 +74,7 @@ const config = { | |
redirectUri: environment.REDIRECT_URI, | ||
clientId: environment.CLIENT_ID, | ||
scope: 'email', | ||
responseType: 'id_token token', | ||
onAuthRequired: onNeedsGlobalAuthenticationGuard | ||
}; | ||
|
||
|
@@ -86,7 +87,7 @@ const config = { | |
declarations: [ | ||
AppComponent, | ||
ProtectedComponent, | ||
SessionTokenLogin | ||
SessionTokenLoginComponent | ||
], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
|
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.
I feel like we should be explicitly mentioning that these are string values.
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.
I thought about noting that in this section, but seems weird to only mention the types on this configuration value. When this value is evaluated, typescript will error due to a type difference.
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.
Aw, types 💘