-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from eaba/oauth2
Oauth2
- Loading branch information
Showing
27 changed files
with
1,372 additions
and
209 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SharpPulsar.Interfaces; | ||
|
||
/// <summary> | ||
/// Licensed to the Apache Software Foundation (ASF) under one | ||
/// or more contributor license agreements. See the NOTICE file | ||
/// distributed with this work for additional information | ||
/// regarding copyright ownership. The ASF licenses this file | ||
/// to you under the Apache License, Version 2.0 (the | ||
/// "License"); you may not use this file except in compliance | ||
/// with the License. You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, | ||
/// software distributed under the License is distributed on an | ||
/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
/// KIND, either express or implied. See the License for the | ||
/// specific language governing permissions and limitations | ||
/// under the License. | ||
/// </summary> | ||
namespace SharpPulsar.Auth.OAuth2 | ||
{ | ||
/// <summary> | ||
/// Provide OAuth 2.0 authentication data. | ||
/// </summary> | ||
[Serializable] | ||
internal class AuthenticationDataOAuth2 : IAuthenticationDataProvider | ||
{ | ||
public const string HttpHeaderName = "Authorization"; | ||
|
||
private readonly string _accessToken; | ||
private readonly ISet<KeyValuePair<string, string>> _headers = new HashSet<KeyValuePair<string, string>>() ; | ||
|
||
public AuthenticationDataOAuth2(string accessToken) | ||
{ | ||
_accessToken = accessToken; | ||
_headers.Add(new KeyValuePair<string, string>(HttpHeaderName, "Bearer " + accessToken)); | ||
} | ||
|
||
public virtual bool HasDataForHttp() | ||
{ | ||
return true; | ||
} | ||
|
||
public virtual ISet<KeyValuePair<string, string>> HttpHeaders | ||
{ | ||
get | ||
{ | ||
return _headers; | ||
} | ||
} | ||
|
||
public virtual bool HasDataFromCommand() | ||
{ | ||
return true; | ||
} | ||
|
||
public virtual string CommandData | ||
{ | ||
get | ||
{ | ||
return _accessToken; | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using SharpPulsar.Interfaces; | ||
/// <summary> | ||
/// Licensed to the Apache Software Foundation (ASF) under one | ||
/// or more contributor license agreements. See the NOTICE file | ||
/// distributed with this work for additional information | ||
/// regarding copyright ownership. The ASF licenses this file | ||
/// to you under the Apache License, Version 2.0 (the | ||
/// "License"); you may not use this file except in compliance | ||
/// with the License. You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, | ||
/// software distributed under the License is distributed on an | ||
/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
/// KIND, either express or implied. See the License for the | ||
/// specific language governing permissions and limitations | ||
/// under the License. | ||
/// </summary> | ||
namespace SharpPulsar.Auth.OAuth2 | ||
{ | ||
/// <summary> | ||
/// Factory class that allows to create <seealso cref="Authentication"/> instances | ||
/// for OAuth 2.0 authentication methods. | ||
/// </summary> | ||
public sealed class AuthenticationFactoryOAuth2 | ||
{ | ||
|
||
/// <summary> | ||
/// Authenticate with client credentials. | ||
/// </summary> | ||
/// <param name="issuerUrl"> the issuer URL </param> | ||
/// <param name="credentialsUrl"> the credentials URL </param> | ||
/// <param name="audience"> An optional field. The audience identifier used by some Identity Providers, like Auth0. </param> | ||
/// <returns> an Authentication object </returns> | ||
public static IAuthentication ClientCredentials(Uri issuerUrl, Uri credentialsUrl, string audience) | ||
{ | ||
return ClientCredentials(issuerUrl, credentialsUrl, audience, null); | ||
} | ||
|
||
/// <summary> | ||
/// Authenticate with client credentials. | ||
/// </summary> | ||
/// <param name="issuerUrl"> the issuer URL </param> | ||
/// <param name="credentialsUrl"> the credentials URL </param> | ||
/// <param name="audience"> An optional field. The audience identifier used by some Identity Providers, like Auth0. </param> | ||
/// <param name="scope"> An optional field. The value of the scope parameter is expressed as a list of space-delimited, | ||
/// case-sensitive strings. The strings are defined by the authorization server. | ||
/// If the value contains multiple space-delimited strings, their order does not matter, | ||
/// and each string adds an additional access range to the requested scope. | ||
/// From here: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4.2 </param> | ||
/// <returns> an Authentication object </returns> | ||
public static IAuthentication ClientCredentials(Uri issuerUrl, Uri credentialsUrl, string audience, string scope) | ||
{ | ||
var flow = new ClientCredentialsFlow(issuerUrl, audience, credentialsUrl.LocalPath, scope); | ||
return new AuthenticationOAuth2(flow, DateTime.Now); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.