Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#64247 fix(simple-oauth2): correct type for…
Browse files Browse the repository at this point in the history
… 'scope' field in PasswordTokenConfig by @pafik13
  • Loading branch information
pafik13 authored Feb 7, 2023
1 parent f216e27 commit f887693
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion types/simple-oauth2/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export interface PasswordTokenConfig {
/** A string that represents the registered password. */
password: string;
/** A string or array of strings that represents the application privileges */
scope: string | string[];
scope?: string | string[];

/**
* Additional options will be automatically serialized as params for the token request.
Expand Down
18 changes: 16 additions & 2 deletions types/simple-oauth2/simple-oauth2-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,29 @@ const oauth2ResourceOwnerPassword = new oauth2lib.ResourceOwnerPassword(

// #Password Credentials Flow
(async () => {
const tokenConfig = {
const tokenConfig1 = {
username: "username",
password: "password",
};

const tokenConfig2 = {
username: "username",
password: "password",
scope: ["<scope1>", "<scope2>"],
};

const tokenConfig3 = {
username: "username",
password: "password",
scope: "<scope1>",
};

// Save the access token
try {
const result = await oauth2ResourceOwnerPassword.getToken(tokenConfig);
let result = await oauth2ResourceOwnerPassword.getToken(tokenConfig1);
result = await oauth2ResourceOwnerPassword.getToken(tokenConfig2);
result = await oauth2ResourceOwnerPassword.getToken(tokenConfig3);

const accessToken = oauth2ResourceOwnerPassword.createToken(result.token);
} catch (error) {
console.log("Access Token Error", error.message);
Expand Down

0 comments on commit f887693

Please sign in to comment.