public void InitializeOAuth2PasswordWorksWithCsdl() { // Arrange string annotation = @"<Annotation Term=""NS.MyOAuth2Password""> <Record > <PropertyValue Property=""RefreshUrl"" String=""http://refreshUrl"" /> <PropertyValue Property=""TokenUrl"" String=""http://tokenUrl"" /> </Record> </Annotation>"; IEdmModel model = GetEdmModel(annotation); Assert.NotNull(model); // guard Assert.NotNull(model.EntityContainer); // Act OAuth2Password password = model.GetRecord <OAuth2Password>(model.EntityContainer, "NS.MyOAuth2Password"); // Assert Assert.Null(password.Name); Assert.Null(password.Description); Assert.Null(password.Scopes); Assert.Equal("http://refreshUrl", password.RefreshUrl); Assert.Equal("http://tokenUrl", password.TokenUrl); }
public void InitializeOAuth2PasswordWithRecordSuccess() { // Arrange IEdmRecordExpression record = new EdmRecordExpression( new EdmPropertyConstructor("RefreshUrl", new EdmStringConstant("http://refreshUrl")), new EdmPropertyConstructor("TokenUrl", new EdmStringConstant("http://tokenUrl"))); OAuth2Password password = new OAuth2Password(); Assert.Null(password.Name); Assert.Null(password.Description); Assert.Null(password.Scopes); Assert.Null(password.RefreshUrl); Assert.Null(password.TokenUrl); // Act password.Initialize(record); // Assert Assert.Null(password.Name); Assert.Null(password.Description); Assert.Null(password.Scopes); Assert.Equal("http://refreshUrl", password.RefreshUrl); Assert.Equal("http://tokenUrl", password.TokenUrl); }
public void SchemeTypeKindAndOAuthTypeSetCorrectly() { // Arrange OAuth2Password password = new OAuth2Password(); // Act & Assert Assert.Equal(SecuritySchemeType.OAuth2, password.SchemeType); Assert.Equal(OAuth2Type.Pasword, password.OAuth2Type); }
private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorization oAuth2) { Debug.Assert(scheme != null); Debug.Assert(oAuth2 != null); scheme.Flows = new OpenApiOAuthFlows(); OpenApiOAuthFlow flow = null; switch (oAuth2.OAuth2Type) { case OAuth2Type.AuthCode: // AuthCode OAuth2AuthCode authCode = (OAuth2AuthCode)oAuth2; flow = new OpenApiOAuthFlow { AuthorizationUrl = new Uri(authCode.AuthorizationUrl), TokenUrl = new Uri(authCode.TokenUrl) }; scheme.Flows.AuthorizationCode = flow; break; case OAuth2Type.Pasword: // Password OAuth2Password password = (OAuth2Password)oAuth2; flow = new OpenApiOAuthFlow { TokenUrl = new Uri(password.TokenUrl) }; scheme.Flows.Password = flow; break; case OAuth2Type.Implicit: // Implicit OAuth2Implicit @implicit = (OAuth2Implicit)oAuth2; flow = new OpenApiOAuthFlow { AuthorizationUrl = new Uri(@implicit.AuthorizationUrl) }; scheme.Flows.Implicit = flow; break; case OAuth2Type.ClientCredentials: // ClientCredentials OAuth2ClientCredentials credentials = (OAuth2ClientCredentials)oAuth2; flow = new OpenApiOAuthFlow { TokenUrl = new Uri(credentials.TokenUrl) }; scheme.Flows.ClientCredentials = flow; break; } Debug.Assert(flow != null); flow.RefreshUrl = new Uri(oAuth2.RefreshUrl); if (oAuth2.Scopes != null) { flow.Scopes = oAuth2.Scopes.ToDictionary(s => s.Scope, s => s.Description); } }
/// <summary> /// Initializes a new instance of the <see cref="OAuth2Authenticator"/> class. /// </summary> /// <param name="client">The OAuth2 client</param> protected OAuth2PasswordAuthenticator(OAuth2Password.OAuth2PasswordClient client) { Client = client; }
/// <summary> /// Initializes a new instance of the <see cref="OAuth2AuthorizationRequestHeaderAuthenticator"/> class. /// </summary> /// <param name="client">The OAuth2 client</param> /// <param name="tokenType"> /// The token type. /// </param> public OAuth2PasswordAuthorizationRequestHeaderAuthenticator(OAuth2Password.OAuth2PasswordClient client, string tokenType) : base(client) { _tokenType = tokenType; }
/// <summary> /// Initializes a new instance of the <see cref="OAuth2AuthorizationRequestHeaderAuthenticator"/> class. /// </summary> /// <param name="client">The OAuth2 client</param> public OAuth2PasswordAuthorizationRequestHeaderAuthenticator(OAuth2Password.OAuth2PasswordClient client) : this(client, (string.IsNullOrEmpty(client.TokenType) ? "OAuth" : client.TokenType)) { }