Skip to content

Commit e5c1368

Browse files
authored
IAM: oauth2 token exchange grant (istio#343)
Adds configuration and API to support token exchange grants.
1 parent 81f08af commit e5c1368

File tree

9 files changed

+616
-172
lines changed

9 files changed

+616
-172
lines changed

generated/jsonschema/tetrateio.api.iam.v2/GrantRequest.jsonschema

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"REFRESH_TOKEN",
99
1,
1010
"DEVICE_CODE_URN",
11-
2
11+
2,
12+
"CLIENT_CREDENTIALS",
13+
3,
14+
"TOKEN_EXCHANGE",
15+
4
1216
],
1317
"oneOf": [
1418
{
@@ -38,6 +42,37 @@
3842
"client_id": {
3943
"type": "string",
4044
"description": "Client ID for which the token grant request is being made.\n This is optional and when absent, TSB will use an appropriate client ID from configuration\n for the grant type being request.\n For a refresh grant type, this parameter may be required to ensure the appropriate client\n configuration is used."
45+
},
46+
"resource": {
47+
"type": "string",
48+
"description": "A URI that indicates the target service or resource where the client intends to use the requested token.\n This is used with the token exchange grant and should be the URI of TSB."
49+
},
50+
"subject_token": {
51+
"type": "string",
52+
"description": "A token that represents the identity of the party on behalf of whom the request is being made.\n This is used with the token exchange grant and should be either an ID Token or Access Token from the configured\n offline token grant client."
53+
},
54+
"subject_token_type": {
55+
"enum": [
56+
"TOKEN_TYPE_UNSPECIFIED",
57+
0,
58+
"TOKEN_TYPE_ACCESS_TOKEN",
59+
1,
60+
"TOKEN_TYPE_REFRESH_TOKEN",
61+
2,
62+
"TOKEN_TYPE_ID_TOKEN",
63+
3,
64+
"TOKEN_TYPE_JWT",
65+
4
66+
],
67+
"oneOf": [
68+
{
69+
"type": "string"
70+
},
71+
{
72+
"type": "integer"
73+
}
74+
],
75+
"description": "An identifier that indicates the type of the security token in the \"subject_token\" parameter.\n This is used with the token exchange grant."
4176
}
4277
},
4378
"additionalProperties": true,

generated/ts/iam/v2/oauth_service_pb.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export class GrantRequest extends jspb.Message {
8383
getClientId(): string;
8484
setClientId(value: string): void;
8585

86+
getResource(): string;
87+
setResource(value: string): void;
88+
89+
getSubjectToken(): string;
90+
setSubjectToken(value: string): void;
91+
92+
getSubjectTokenType(): TokenTypeMap[keyof TokenTypeMap];
93+
setSubjectTokenType(value: TokenTypeMap[keyof TokenTypeMap]): void;
94+
8695
serializeBinary(): Uint8Array;
8796
toObject(includeInstance?: boolean): GrantRequest.AsObject;
8897
static toObject(includeInstance: boolean, msg: GrantRequest): GrantRequest.AsObject;
@@ -100,6 +109,9 @@ export namespace GrantRequest {
100109
refreshToken: string,
101110
scopeList: Array<string>,
102111
clientId: string,
112+
resource: string,
113+
subjectToken: string,
114+
subjectTokenType: TokenTypeMap[keyof TokenTypeMap],
103115
}
104116
}
105117

@@ -151,6 +163,8 @@ export interface GrantTypeMap {
151163
UNSPECIFIED: 0;
152164
REFRESH_TOKEN: 1;
153165
DEVICE_CODE_URN: 2;
166+
CLIENT_CREDENTIALS: 3;
167+
TOKEN_EXCHANGE: 4;
154168
}
155169

156170
export const GrantType: GrantTypeMap;
@@ -171,3 +185,13 @@ export interface ErrorMap {
171185

172186
export const Error: ErrorMap;
173187

188+
export interface TokenTypeMap {
189+
TOKEN_TYPE_UNSPECIFIED: 0;
190+
TOKEN_TYPE_ACCESS_TOKEN: 1;
191+
TOKEN_TYPE_REFRESH_TOKEN: 2;
192+
TOKEN_TYPE_ID_TOKEN: 3;
193+
TOKEN_TYPE_JWT: 4;
194+
}
195+
196+
export const TokenType: TokenTypeMap;
197+

generated/ts/iam/v2/oauth_service_pb.js

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ goog.exportSymbol('proto.tetrateio.api.iam.v2.Error', null, global);
2525
goog.exportSymbol('proto.tetrateio.api.iam.v2.GrantRequest', null, global);
2626
goog.exportSymbol('proto.tetrateio.api.iam.v2.GrantResponse', null, global);
2727
goog.exportSymbol('proto.tetrateio.api.iam.v2.GrantType', null, global);
28+
goog.exportSymbol('proto.tetrateio.api.iam.v2.TokenType', null, global);
2829
/**
2930
* Generated by JsPbCodeGenerator.
3031
* @param {Array=} opt_data Optional initial data array, typically from a
@@ -563,7 +564,10 @@ proto.tetrateio.api.iam.v2.GrantRequest.toObject = function(includeInstance, msg
563564
deviceCode: jspb.Message.getFieldWithDefault(msg, 2, ""),
564565
refreshToken: jspb.Message.getFieldWithDefault(msg, 3, ""),
565566
scopeList: (f = jspb.Message.getRepeatedField(msg, 4)) == null ? undefined : f,
566-
clientId: jspb.Message.getFieldWithDefault(msg, 5, "")
567+
clientId: jspb.Message.getFieldWithDefault(msg, 5, ""),
568+
resource: jspb.Message.getFieldWithDefault(msg, 6, ""),
569+
subjectToken: jspb.Message.getFieldWithDefault(msg, 7, ""),
570+
subjectTokenType: jspb.Message.getFieldWithDefault(msg, 8, 0)
567571
};
568572

569573
if (includeInstance) {
@@ -620,6 +624,18 @@ proto.tetrateio.api.iam.v2.GrantRequest.deserializeBinaryFromReader = function(m
620624
var value = /** @type {string} */ (reader.readString());
621625
msg.setClientId(value);
622626
break;
627+
case 6:
628+
var value = /** @type {string} */ (reader.readString());
629+
msg.setResource(value);
630+
break;
631+
case 7:
632+
var value = /** @type {string} */ (reader.readString());
633+
msg.setSubjectToken(value);
634+
break;
635+
case 8:
636+
var value = /** @type {!proto.tetrateio.api.iam.v2.TokenType} */ (reader.readEnum());
637+
msg.setSubjectTokenType(value);
638+
break;
623639
default:
624640
reader.skipField();
625641
break;
@@ -684,6 +700,27 @@ proto.tetrateio.api.iam.v2.GrantRequest.serializeBinaryToWriter = function(messa
684700
f
685701
);
686702
}
703+
f = message.getResource();
704+
if (f.length > 0) {
705+
writer.writeString(
706+
6,
707+
f
708+
);
709+
}
710+
f = message.getSubjectToken();
711+
if (f.length > 0) {
712+
writer.writeString(
713+
7,
714+
f
715+
);
716+
}
717+
f = message.getSubjectTokenType();
718+
if (f !== 0.0) {
719+
writer.writeEnum(
720+
8,
721+
f
722+
);
723+
}
687724
};
688725

689726

@@ -796,6 +833,60 @@ proto.tetrateio.api.iam.v2.GrantRequest.prototype.setClientId = function(value)
796833
};
797834

798835

836+
/**
837+
* optional string resource = 6;
838+
* @return {string}
839+
*/
840+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.getResource = function() {
841+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, ""));
842+
};
843+
844+
845+
/**
846+
* @param {string} value
847+
* @return {!proto.tetrateio.api.iam.v2.GrantRequest} returns this
848+
*/
849+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.setResource = function(value) {
850+
return jspb.Message.setProto3StringField(this, 6, value);
851+
};
852+
853+
854+
/**
855+
* optional string subject_token = 7;
856+
* @return {string}
857+
*/
858+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.getSubjectToken = function() {
859+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 7, ""));
860+
};
861+
862+
863+
/**
864+
* @param {string} value
865+
* @return {!proto.tetrateio.api.iam.v2.GrantRequest} returns this
866+
*/
867+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.setSubjectToken = function(value) {
868+
return jspb.Message.setProto3StringField(this, 7, value);
869+
};
870+
871+
872+
/**
873+
* optional TokenType subject_token_type = 8;
874+
* @return {!proto.tetrateio.api.iam.v2.TokenType}
875+
*/
876+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.getSubjectTokenType = function() {
877+
return /** @type {!proto.tetrateio.api.iam.v2.TokenType} */ (jspb.Message.getFieldWithDefault(this, 8, 0));
878+
};
879+
880+
881+
/**
882+
* @param {!proto.tetrateio.api.iam.v2.TokenType} value
883+
* @return {!proto.tetrateio.api.iam.v2.GrantRequest} returns this
884+
*/
885+
proto.tetrateio.api.iam.v2.GrantRequest.prototype.setSubjectTokenType = function(value) {
886+
return jspb.Message.setProto3EnumField(this, 8, value);
887+
};
888+
889+
799890

800891

801892

@@ -1112,7 +1203,9 @@ proto.tetrateio.api.iam.v2.GrantResponse.prototype.setErrorMessage = function(va
11121203
proto.tetrateio.api.iam.v2.GrantType = {
11131204
UNSPECIFIED: 0,
11141205
REFRESH_TOKEN: 1,
1115-
DEVICE_CODE_URN: 2
1206+
DEVICE_CODE_URN: 2,
1207+
CLIENT_CREDENTIALS: 3,
1208+
TOKEN_EXCHANGE: 4
11161209
};
11171210

11181211
/**
@@ -1132,4 +1225,15 @@ proto.tetrateio.api.iam.v2.Error = {
11321225
SERVER_ERROR: 10
11331226
};
11341227

1228+
/**
1229+
* @enum {number}
1230+
*/
1231+
proto.tetrateio.api.iam.v2.TokenType = {
1232+
TOKEN_TYPE_UNSPECIFIED: 0,
1233+
TOKEN_TYPE_ACCESS_TOKEN: 1,
1234+
TOKEN_TYPE_REFRESH_TOKEN: 2,
1235+
TOKEN_TYPE_ID_TOKEN: 3,
1236+
TOKEN_TYPE_JWT: 4
1237+
};
1238+
11351239
goog.object.extend(exports, proto.tetrateio.api.iam.v2);

0 commit comments

Comments
 (0)