Skip to content

@azure/identity-TokenCredential #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
999b114
Adding token credential auth provider
nikithauc Sep 25, 2020
9e4db10
testing with samplenpm
nikithauc Sep 29, 2020
0dab297
Adding client secret cred flow
nikithauc Nov 13, 2020
6e74cda
Adding unit tests
nikithauc Nov 28, 2020
a56a103
package json change
nikithauc Nov 29, 2020
7f12ab6
Adding readme docs
nikithauc Nov 29, 2020
d70b08a
Adding project references from spec and aut
nikithauc Dec 16, 2020
ba0947d
temporarily resetting package json
nikithauc Dec 23, 2020
40e1a43
Merge with dev
nikithauc Dec 23, 2020
862081c
Updating to isomorphic-fetch 3.00, commenting some tests
nikithauc Dec 23, 2020
d89f994
Exporting authProviders from lib folder
nikithauc Dec 23, 2020
8c57c0a
Exporting authProviders from lib folder
nikithauc Dec 23, 2020
2cfaf69
Keywords, msal files path change
nikithauc Jan 3, 2021
0bcb659
Resetting file, removing empty references
nikithauc Jan 3, 2021
6f6c690
Merge branch 'dev' into Authentication
nikithauc Jan 4, 2021
39d242e
Create versionTest.yml
nikithauc Jan 5, 2021
1967788
Delete versionTest.yml
nikithauc Jan 5, 2021
e169e3c
Merging with 3.0.0
nikithauc Jan 7, 2021
48d5a01
Merge branch 'Authentication' of https://github.com/microsoftgraph/ms…
nikithauc Jan 7, 2021
a7e1a62
merge with 3.0.0
nikithauc Jan 7, 2021
7da0d9f
refactoring with error conditions and test merge
nikithauc Jan 12, 2021
c61af2e
Adding note and karma file path
nikithauc Jan 12, 2021
571bdaf
adding js sample
nikithauc Jan 13, 2021
dfce4fd
Correcting doc language errors
nikithauc Jan 13, 2021
7e39e1b
Update docs/TokenCredentialAuthenticationProvider.md
nikithauc Jan 13, 2021
fee04ec
Update docs/TokenCredentialAuthenticationProvider.md
nikithauc Jan 20, 2021
3a2fe1b
Update samples/tokenCredentialSamples/ClientCredentialFlow/README.md
nikithauc Jan 20, 2021
6c296a0
Re-adding peerdependency meta in package.json
nikithauc Jan 21, 2021
c9aff66
Merge branch 'Authentication' of https://github.com/microsoftgraph/ms…
nikithauc Jan 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ src/**/*.js
src/**/*.js.map
src/**/*.d.ts

samples/**/*/secrets.ts
samples/**/*/secrets.js
samples/**/secrets.ts
samples/**/secrets.js
samples/node/secrets.json
samples/browser/src/secrets.js
samples/browser/src/graph-js-sdk.js
Expand Down
2 changes: 1 addition & 1 deletion docs/ImplicitMSALAuthenticationProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Refer devDependencies in [package.json](../package.json) for the compatible msal version and update that version in below.

**Important Note:** MSAL is supported only for frontend applications, for server-side authentication you have to can use [TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md) or implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
**Important Note:** MSAL is supported only for frontend applications, for server-side authentication you either can use [TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md) or implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).

```html
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/<version>/js/msal.min.js"></script>
Expand Down
14 changes: 7 additions & 7 deletions docs/TokenCredentialAuthenticationProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

- Check the [tokenCredentialSamples folder][../samples/tokencredentialsamples]. The ClientSecretCredentialFlow is an example of using TokenCredential to authenticate a node application. The AuthenticationCodeFlow is an example of using TokenCredential to authenticate a browser application.

**Important Note:** TokenCredentials can be used to authentication browser and node applications.
**Important Note:** TokenCredentials can be used to authenticate browser and node applications.

###### Example of how to create and pass a token credential sample -
###### Example of how to create and pass a token credential -

```typescript
// Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential
// Import the TokenCredential class that you wish to use. This example uses a Client SecretCredential

import { ClientSecretCredential } from "@azure/identity";
import { TokenCredentialAuthenticationProvider, TokenCredentialAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";

// Create an instance of the TokenCredential Class that is imported
// Create an instance of the TokenCredential class that is imported
const tokenCredential = new ClientSecretCredential("your_tenantId", "your_clientId", "your_clientSecret");

// Set your scopes and options for TokenCredential.getToken (Check the ` interface GetTokenOptions` in (TokenCredential Implementation)[https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts])

const options: TokenCredentialAuthenticationProviderOptions = { scopes: [scopes], getTokenoptions };
const options: TokenCredentialAuthenticationProviderOptions = { scopes: [scopes], getTokenOtions };

// Create an instance of the TokenCredentialAuthenticationProvider by passing the tokenCredential instance and options to the constructor
const authProvider = new TokenCredentialAuthenticationProvider(tokenCredential, options);
Expand All @@ -35,13 +35,13 @@ const res = await client.api("/users/").get();
```

```javascript
// Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential
// Import the TokenCredential class that you wish to use. This examples uses a ClientSecretCredential

const { ClientSecretCredential } = require("@azure/identity");
const { Client } = require("@microsoft/microsoft-graph-client");
const { TokenCredentialAuthenticationProvider } = require("@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials");

// Create an instance of the TokenCredential Class that is imported
// Create an instance of the TokenCredential class that is imported
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);

// Set your scopes and options for TokenCredential.getToken (Check the ` interface GetTokenOptions` in (TokenCredential Implementation)[https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

4. Navigate to authenticationCodeFlow samples directory [./samples/tokenCredentialSamples/authenticationCodeFlow]

5.Run `npm start` to build and start the application.
5. Run `npm start` to build and start the application.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ async function getCredential(): Promise<AuthorizationCodeCredential> {
// Direct the user to the authentication URI either by opening a
// browser (desktop and mobile apps) or redirecting their browser
// using a Location header (web apps and APIs).
const authenticateUrl = getAuthorizeUrl(tenantId!, clientId!, scopes);
console.log("Opening user's browser to URL:", authenticateUrl);
await open(authenticateUrl);
const authorizeUrl = getAuthorizeUrl(tenantId!, clientId!, scopes);
console.log("Opening user's browser to URL:", authorizeUrl);
await open(authorizeUrl);

// Wait for the authorization response to be send to the redirect URI
const authorizationCode = await authCodePromise;
console.log("\nReceived authorization code:", authorizationCode);

// Once we have the authorization code, the AuthorizationCodeCredential
// can be created. This credential will take care of requesting and
// can be created. This credential will take care of requesting and
// refreshing the access token from this point forward.
if (clientSecret) {
return new AuthorizationCodeCredential(
Expand All @@ -84,7 +84,7 @@ async function getCredential(): Promise<AuthorizationCodeCredential> {
redirectUri,
// NOTE: It is not necessary to explicitly pass the authorityHost when using
// the default authority host: https://login.microsoftonline.com. It is only
// necesary when a different authority host is used in the initial authorization
// necessary when a different authority host is used in the initial authorization
// URI.
{ authorityHost },
);
Expand Down
4 changes: 2 additions & 2 deletions samples/tokenCredentialSamples/ClientCredentialFlow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

- [Register an application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app)

- [documention](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application).
- [Documention](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application).

2. Rename [secrets.sample.ts](./typescript/secrets.sample.ts) to secrets.ts or rename [secrets.sample.js](./javascript/secrets.sample.js) to secrets.js

3. Update your clientId, tenantId, scopes, clientSecret in the **secrets.ts/secrets.js)** file.
3. Update your clientId, tenantId, scopes, clientSecret in the **secrets.ts/secrets.js** file.

## Run Sample

Expand Down