Skip to content
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

Added Organization to OAuth2. #7435

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/insomnia-sdk/src/objects/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ describe('test auth transforming', () => {
pkceMethod: 'pkceMethod',
responseType: 'id_token',
origin: 'origin',
organization: 'org',
};

[
Expand Down
8 changes: 8 additions & 0 deletions packages/insomnia-sdk/src/objects/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export function fromPreRequestAuth(auth: RequestAuth): RequestAuthentication {
refreshToken: findValueInOauth2Options('refreshTokenUrl', authObj.oauth2),
credentialsInBody: findValueInOauth2Options('client_authentication', authObj.oauth2) === 'body',
audience: findValueInOauth2Options('audience', authObj.oauth2) || '',
organization: findValueInOauth2Options('organization', authObj.oauth2) || '',
resource: findValueInOauth2Options('resource', authObj.oauth2) || '',
// following properties are not supported yet in the script side, just try to find and set them
tokenPrefix: findValueInOauth2Options('tokenPrefix', authObj.oauth2),
Expand Down Expand Up @@ -681,6 +682,13 @@ export function toPreRequestAuth(auth: RequestAuthentication | {}): AuthOptions
send_as: 'request_url', // request_body or request_header

},
{
key: 'organization',
value: auth.organization || '',
enabled: true,
send_as: 'request_url', // request_body or request_header

},
],
},

Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/models/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface AuthTypeOAuth2 {
pkceMethod?: string;
responseType?: OAuth2ResponseType;
origin?: string;
organization?: string;
}
export interface AuthTypeHawk {
type: typeof AUTH_HAWK;
Expand Down
3 changes: 2 additions & 1 deletion packages/insomnia/src/network/o-auth-2/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type AuthKeys =
'token_type' |
'username' |
'xError' |
'xResponseId';
'xResponseId' |
'organization';
export const PKCE_CHALLENGE_S256 = 'S256';
export const PKCE_CHALLENGE_PLAIN = 'plain';
5 changes: 5 additions & 0 deletions packages/insomnia/src/network/o-auth-2/get-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const getOAuth2Token = async (
...insertAuthKeyIf('scope', authentication.scope),
...insertAuthKeyIf('state', authentication.state),
...insertAuthKeyIf('audience', authentication.audience),
...insertAuthKeyIf('organization', authentication.organization),
...(hasNonce ? [{
name: 'nonce', value: Math.floor(Math.random() * 9999999999999) + 1 + '',
}] : []),
Expand Down Expand Up @@ -105,6 +106,7 @@ export const getOAuth2Token = async (
...insertAuthKeyIf('state', authentication.state),
...insertAuthKeyIf('audience', authentication.audience),
...insertAuthKeyIf('resource', authentication.resource),
...insertAuthKeyIf('organization', authentication.organization),
...(codeChallenge ? [
{ name: 'code_challenge', value: codeChallenge },
{ name: 'code_challenge_method', value: authentication.pkceMethod },
Expand Down Expand Up @@ -134,6 +136,7 @@ export const getOAuth2Token = async (
...insertAuthKeyIf('audience', authentication.audience),
...insertAuthKeyIf('resource', authentication.resource),
...insertAuthKeyIf('code_verifier', codeVerifier),
...insertAuthKeyIf('organization', authentication.organization),
];
} else if (authentication.grantType === 'password') {
params = [
Expand All @@ -142,13 +145,15 @@ export const getOAuth2Token = async (
...insertAuthKeyIf('password', authentication.password),
...insertAuthKeyIf('scope', authentication.scope),
...insertAuthKeyIf('audience', authentication.audience),
...insertAuthKeyIf('organization', authentication.organization),
];
} else if (authentication.grantType === 'client_credentials') {
params = [
{ name: 'grant_type', value: 'client_credentials' },
...insertAuthKeyIf('scope', authentication.scope),
...insertAuthKeyIf('audience', authentication.audience),
...insertAuthKeyIf('resource', authentication.resource),
...insertAuthKeyIf('organization', authentication.organization),
];
}
const headers = authentication.origin ? [{ name: 'Origin', value: authentication.origin }] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const getFields = (authentication: Extract<RequestAuthentication, { type: typeof
help='Indicates the type of credentials returned in the response'
/>;
const audience = <AuthInputRow label='Audience' property='audience' key='audience' help='Indicate what resource server to access' />;
const organization = <AuthInputRow label='Organization' property='organization' key='organization' help='Indicate what Organization the client belongs to' />;
const resource = <AuthInputRow label='Resource' property='resource' key='resource' help='Indicate what resource to access' />;
const origin = <AuthInputRow label='Origin' property='origin' key='origin' help='Specify Origin header when CORS is required for oauth endpoints' />;
const credentialsInBody = <AuthSelectRow
Expand All @@ -142,6 +143,7 @@ const getFields = (authentication: Extract<RequestAuthentication, { type: typeof
tokenPrefix,
responseType,
audience,
organization,
resource,
origin,
credentialsInBody,
Expand All @@ -167,6 +169,7 @@ const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, {
resource,
origin,
credentialsInBody,
organization,
} = getFields(authentication);

const { grantType } = authentication;
Expand All @@ -193,6 +196,7 @@ const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, {
audience,
resource,
origin,
organization,
];
} else if (grantType === GRANT_TYPE_CLIENT_CREDENTIALS) {
basic = [
Expand All @@ -207,6 +211,7 @@ const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, {
tokenPrefix,
audience,
resource,
organization,
];
} else if (grantType === GRANT_TYPE_PASSWORD) {
basic = [
Expand All @@ -222,6 +227,7 @@ const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, {
credentialsInBody,
tokenPrefix,
audience,
organization,
];
} else if (grantType === GRANT_TYPE_IMPLICIT) {
basic = [
Expand All @@ -236,6 +242,7 @@ const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, {
state,
tokenPrefix,
audience,
organization,
];
}

Expand Down