-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiOAuthFlow.cs
More file actions
111 lines (92 loc) · 3.96 KB
/
OpenApiOAuthFlow.cs
File metadata and controls
111 lines (92 loc) · 3.96 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;
namespace Microsoft.OpenApi.Models
{
/// <summary>
/// OAuth Flow Object.
/// </summary>
public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible
{
/// <summary>
/// REQUIRED. The authorization URL to be used for this flow.
/// Applies to implicit and authorizationCode OAuthFlow.
/// </summary>
public Uri? AuthorizationUrl { get; set; }
/// <summary>
/// REQUIRED. The token URL to be used for this flow.
/// Applies to password, clientCredentials, and authorizationCode OAuthFlow.
/// </summary>
public Uri? TokenUrl { get; set; }
/// <summary>
/// The URL to be used for obtaining refresh tokens.
/// </summary>
public Uri? RefreshUrl { get; set; }
/// <summary>
/// REQUIRED. A map between the scope name and a short description for it.
/// </summary>
public IDictionary<string, string>? Scopes { get; set; }
/// <summary>
/// Specification Extensions.
/// </summary>
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiOAuthFlow() { }
/// <summary>
/// Initializes a copy of an <see cref="OpenApiOAuthFlow"/> object
/// </summary>
public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow)
{
AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
Scopes = oAuthFlow?.Scopes != null ? new Dictionary<string, string>(oAuthFlow.Scopes) : null;
Extensions = oAuthFlow?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(oAuthFlow.Extensions) : null;
}
/// <summary>
/// Serialize <see cref="OpenApiOAuthFlow"/> to Open Api v3.1
/// </summary>
public void SerializeAsV31(IOpenApiWriter writer)
{
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
}
/// <summary>
/// Serialize <see cref="OpenApiOAuthFlow"/> to Open Api v3.0
/// </summary>
public void SerializeAsV3(IOpenApiWriter writer)
{
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
}
/// <summary>
/// Serialize <see cref="OpenApiOAuthFlow"/> to Open Api v3.0
/// </summary>
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
{
Utils.CheckArgumentNull(writer);
writer.WriteStartObject();
// authorizationUrl
writer.WriteProperty(OpenApiConstants.AuthorizationUrl, AuthorizationUrl?.ToString());
// tokenUrl
writer.WriteProperty(OpenApiConstants.TokenUrl, TokenUrl?.ToString());
// refreshUrl
writer.WriteProperty(OpenApiConstants.RefreshUrl, RefreshUrl?.ToString());
// scopes
writer.WriteRequiredMap(OpenApiConstants.Scopes, Scopes, (w, s) => w.WriteValue(s));
// extensions
writer.WriteExtensions(Extensions, version);
writer.WriteEndObject();
}
/// <summary>
/// Serialize <see cref="OpenApiOAuthFlow"/> to Open Api v2.0
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)
{
// OAuthFlow object does not exist in V2.
}
}
}