/
authentication.ts
121 lines (115 loc) · 4.09 KB
/
authentication.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { Authentication } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { GeneratedClient } from "../generatedClient";
import {
PostContentSchemaGrantType,
AuthenticationExchangeAadAccessTokenForAcrRefreshTokenOptionalParams,
AuthenticationExchangeAadAccessTokenForAcrRefreshTokenResponse,
TokenGrantType,
AuthenticationExchangeAcrRefreshTokenForAcrAccessTokenOptionalParams,
AuthenticationExchangeAcrRefreshTokenForAcrAccessTokenResponse
} from "../models";
/** Class containing Authentication operations. */
export class AuthenticationImpl implements Authentication {
private readonly client: GeneratedClient;
/**
* Initialize a new instance of the class Authentication class.
* @param client Reference to the service client
*/
constructor(client: GeneratedClient) {
this.client = client;
}
/**
* Exchange AAD tokens for an ACR refresh Token
* @param grantType Can take a value of access_token_refresh_token, or access_token, or refresh_token
* @param service Indicates the name of your Azure container registry.
* @param options The options parameters.
*/
exchangeAadAccessTokenForAcrRefreshToken(
grantType: PostContentSchemaGrantType,
service: string,
options?: AuthenticationExchangeAadAccessTokenForAcrRefreshTokenOptionalParams
): Promise<AuthenticationExchangeAadAccessTokenForAcrRefreshTokenResponse> {
return this.client.sendOperationRequest(
{ grantType, service, options },
exchangeAadAccessTokenForAcrRefreshTokenOperationSpec
);
}
/**
* Exchange ACR Refresh token for an ACR Access Token
* @param service Indicates the name of your Azure container registry.
* @param scope Which is expected to be a valid scope, and can be specified more than once for multiple
* scope requests. You obtained this from the Www-Authenticate response header from the challenge.
* @param refreshToken Must be a valid ACR refresh token
* @param grantType Grant type is expected to be refresh_token
* @param options The options parameters.
*/
exchangeAcrRefreshTokenForAcrAccessToken(
service: string,
scope: string,
refreshToken: string,
grantType: TokenGrantType,
options?: AuthenticationExchangeAcrRefreshTokenForAcrAccessTokenOptionalParams
): Promise<AuthenticationExchangeAcrRefreshTokenForAcrAccessTokenResponse> {
return this.client.sendOperationRequest(
{ service, scope, refreshToken, grantType, options },
exchangeAcrRefreshTokenForAcrAccessTokenOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const exchangeAadAccessTokenForAcrRefreshTokenOperationSpec: coreClient.OperationSpec = {
path: "/oauth2/exchange",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.AcrRefreshToken
},
default: {
bodyMapper: Mappers.AcrErrors
}
},
formDataParameters: [
Parameters.grantType,
Parameters.service,
Parameters.tenant,
Parameters.refreshToken,
Parameters.accessToken
],
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.url],
headerParameters: [Parameters.contentType3, Parameters.accept4],
serializer
};
const exchangeAcrRefreshTokenForAcrAccessTokenOperationSpec: coreClient.OperationSpec = {
path: "/oauth2/token",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.AcrAccessToken
},
default: {
bodyMapper: Mappers.AcrErrors
}
},
formDataParameters: [
Parameters.service,
Parameters.scope,
Parameters.refreshToken1,
Parameters.grantType1
],
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.url],
headerParameters: [Parameters.contentType3, Parameters.accept4],
serializer
};