You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plan to use ngx-admin template to qury microsoft graph api
To do so i need my app to recover two tokens
Token 1 : Authorisation token
Token2 : Acess token
Currently i can successfully negotiate the first token as code request from endpoint oauth2/authorize?
However when i attempt to post the authorization token to the second endpoint oauth2/token? to recover an acess token Microsoft complains as follows {error: "invalid_request",…} correlation_id : "b5cb3397-b008-4bb0-b475-76ea8deab6c7" error : "invalid_request" error_codes : [90014] error_description : "AADSTS90014: The request body must contain the following parameter: 'grant_type'. ↵Trace ID: d74fbb29-bea3-4bca-b663-b09f65713900 ↵Correlation ID: b5cb3397-b008-4bb0-b475-76ea8deab6c7 ↵Timestamp: 2018-11-02 09:18:53Z" timestamp : "2018-11-02 09:18:53Z" trace_id : "d74fbb29-bea3-4bca-b663-b09f65713900"
For a reference here is the post request as recovered from network debugging POST https://login.microsoftonline.com/xxxxxxxxxxxxxxxxx/oauth2/token?
REQUEST BODY
{"grant_type":"authorization_code","code":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx","redirect_uri":"http://localhost:4200/pages/azure/callback","client_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
Expect to be able to negotiate the second transaction
Is there a option to enable application/x-www-form-urlencoded for the second trasaction Steps to reproduce:
ngx-admin leveraging oauth2
Related code:
oauth2.module.ts
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { NgModule } from '@angular/core';
import { ThemeModule } from '../../../@theme/theme.module';
import { Oauth2RoutingModule, routedComponents } from './oauth2-routing.module';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import {
NbAuthModule,
NbOAuth2AuthStrategy,
NbOAuth2ResponseType,
NbAuthOAuth2Token,
NbOAuth2GrantType,
NbAuthJWTToken,
} from '@nebular/auth';
@NgModule({
imports: [
ThemeModule,
FormsModule,
HttpClientModule,
Oauth2RoutingModule,
NbAuthModule.forRoot({
strategies: [
NbOAuth2AuthStrategy.setup({
name: 'azure',
clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxx',
authorize: {
endpoint: 'https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxx/oauth2/authorize?',
responseType: NbOAuth2ResponseType.CODE,
scope: 'https://graph.microsoft.com',
redirectUri: 'http://localhost:4200/pages/azure/callback',
//params: {'resource' : 'https://graph.microsoft.com'}
},
token: {
endpoint: 'https://login.microsoftonline.com/1d2d8da4-2bcf-4021-a2c2-55cf9b00db5b/oauth2/token?',
redirectUri: 'http://localhost:4200/pages/azure/callback',
class: NbAuthJWTToken, // NbAuthOAuth2Token,
},
redirect: {
success: '/pages/azure',
},
},),
],
}),
],
declarations: [
...routedComponents,
],
})
export class NbOAuth2Module {
}
oauth2-login.component.ts
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { NbMenuService } from '@nebular/theme';
import { Component, OnDestroy } from '@angular/core';
import { NbAuthOAuth2Token, NbAuthResult, NbAuthService } from '@nebular/auth';
import { takeWhile } from 'rxjs/operators';
@Component({
selector: 'ngx-oauth2-login',
styleUrls: ['./oauth2-login.component.scss'],
templateUrl: './oauth2-login.component.html',
})
export class NbOAuth2LoginComponent implements OnDestroy {
token: NbAuthOAuth2Token;
alive = true;
constructor(private authService: NbAuthService) {
this.authService.onTokenChange()
.pipe(takeWhile(() => this.alive))
.subscribe((token: NbAuthOAuth2Token) => {
this.token = null;
if (token && token.isValid()) {
this.token = token;
}
});
}
login() {
this.authService.authenticate('azure')
.pipe(takeWhile(() => this.alive))
.subscribe((authResult: NbAuthResult) => {
});
}
logout() {
this.authService.logout('azure')
.pipe(takeWhile(() => this.alive))
.subscribe((authResult: NbAuthResult) => {
});
}
ngOnDestroy(): void {
this.alive = false;
}
}
oauth2-callback.component.ts
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { NbMenuService } from '@nebular/theme';
import { Component, OnDestroy } from '@angular/core';
import { NbAuthResult, NbAuthService } from '@nebular/auth';
import { Router } from '@angular/router';
import { takeWhile } from 'rxjs/operators';
@Component({
selector: 'ngx-oauth2-callback',
styleUrls: ['./oauth2-callback.component.scss'],
templateUrl: './oauth2-callback.component.html',
})
export class NbOAuth2CallbackComponent implements OnDestroy {
alive = true;
constructor(private authService: NbAuthService, private router: Router) {
this.authService.authenticate('azure')
.pipe(takeWhile(() => this.alive))
.subscribe((authResult: NbAuthResult) => {
if (authResult.isSuccess() && authResult.getRedirect()) {
this.router.navigateByUrl(authResult.getRedirect());
}
});
}
ngOnDestroy(): void {
this.alive = false;
}
}
Had some luck in solving (dirty hack ) this issue myself .
Working of the recent fix #716
I was able to get the azure oauth2 code grant flow working by adding the following to my nebular/auth files
Issue type
I'm submitting a ... (check one with "x")
Issue description
Attempting to leverage ngx-admin templates to recover azure acess tokens with
Azure OAuth 2.0 code grant flow. https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code
Current behavior:
Plan to use ngx-admin template to qury microsoft graph api
To do so i need my app to recover two tokens
Currently i can successfully negotiate the first token as code request from endpoint oauth2/authorize?
However when i attempt to post the authorization token to the second endpoint oauth2/token? to recover an acess token Microsoft complains as follows
{error: "invalid_request",…} correlation_id : "b5cb3397-b008-4bb0-b475-76ea8deab6c7" error : "invalid_request" error_codes : [90014] error_description : "AADSTS90014: The request body must contain the following parameter: 'grant_type'. ↵Trace ID: d74fbb29-bea3-4bca-b663-b09f65713900 ↵Correlation ID: b5cb3397-b008-4bb0-b475-76ea8deab6c7 ↵Timestamp: 2018-11-02 09:18:53Z" timestamp : "2018-11-02 09:18:53Z" trace_id : "d74fbb29-bea3-4bca-b663-b09f65713900"
For a reference here is the post request as recovered from network debugging
POST https://login.microsoftonline.com/xxxxxxxxxxxxxxxxx/oauth2/token?
Stack overflow post point out that the second endpoint expects payload as
xml-endoded
https://stackoverflow.com/questions/48996804/azure-active-directory-aadsts90014-invalid-request
Expected behavior:
Expect to be able to negotiate the second transaction
Is there a option to enable application/x-www-form-urlencoded for the second trasaction
Steps to reproduce:
ngx-admin leveraging oauth2
Related code:
oauth2.module.ts
oauth2-login.component.ts
oauth2-callback.component.ts
Other information:
npm, node, OS, Browser
Angular, Nebular
The text was updated successfully, but these errors were encountered: