1.0.0 • Published 4 years ago

@bechtel/oauth-utility200 v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

oauth-utility

eFrame Authorization Package

Authentication for client crediential grant_type

export interface Options {
  url?: string;
  accessTokenUri?: string;
  clientId?: string;
  clientSecret?: string;
  scopes?: string;
  query?: any;
  headers?: string;
  body?: any;
  method?: string;
  grantType?: string;
  redirectUri?: string;
  state?: string;
  authorizationUri?: string;
  service?: string;
}
  • clientId : provide username /client id
  • clientSecret : provide password or client secret
  • grantType : 'client_credentials'

example

  option={
     method: 'POST',
     clientId: 'apicjchdtdstg',
    clientSecret: 'eeeuhebebebvegtygdbcjlSUBiDthqYVDdmneV3',
    accessTokenUri : 'https://server/as/token.oauth2',
    grantType: "client_credentials"
      };


    var githubAuth=new ClientOAuth2(option );
    let data=await githubAuth.credentials.getToken();

Authentication for authorization_code grant_type

create IOption object and pass it to ClientOAuth2 constructor

 let option:Options;
    option={
      clientId: 'test',
      clientSecret: 'testvalue',
      accessTokenUri: 'https://server/openam/oauth2/access_token',
      authorizationUri: 'https://server/openam/oauth2/authorize',
      redirectUri: 'http://localhost:8080/route',
      scopes: 'scopes,
      grantType : 'authorization_code',
      method:'post',
      service:'abcd'
        };
var githubAuth=new ClientOAuth2(option);

Steps 1: to get the code

 let uri= githubAuth.codeFlow.getUri();
 res.redirect(uri);

Steps 2: to get access token etc

 let data=await githubAuth.codeFlow.accessToken(code);
   - Param code = value receive from the first step
   - data = get value from the forge rock

Steps 3: to get refresh token

let token=await githubAuth.codeFlow.refreshToken(data.refresh_token);

Install

npm install @bechtel/oauth-utility
1.0.0

4 years ago