Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Body40" /> class.
 /// </summary>
 /// <param name="clientId">clientId (required).</param>
 /// <param name="clientSecret">clientSecret (required).</param>
 /// <param name="code">code.</param>
 /// <param name="grantType">grantType (required).</param>
 /// <param name="refreshToken">refreshToken.</param>
 public Body40(string clientId = default(string), string clientSecret = default(string), string code = default(string), GrantTypeEnum grantType = default(GrantTypeEnum), string refreshToken = default(string))
 {
     // to ensure "clientId" is required (not null)
     if (clientId == null)
     {
         throw new InvalidDataException("clientId is a required property for Body40 and cannot be null");
     }
     else
     {
         this.ClientId = clientId;
     }
     // to ensure "clientSecret" is required (not null)
     if (clientSecret == null)
     {
         throw new InvalidDataException("clientSecret is a required property for Body40 and cannot be null");
     }
     else
     {
         this.ClientSecret = clientSecret;
     }
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for Body40 and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     this.Code         = code;
     this.RefreshToken = refreshToken;
 }
Пример #2
0
        public async Task <IHttpActionResult> GetTokenAsync(GrantTypeEnum grantType, string clientId, string clientSecret, string account = "", string pwd = "")
        {
            var dict = new Dictionary <string, string>
            {
                { "clientId", clientId },
                { "clientSecret", clientSecret }
            };

            switch (grantType)
            {
            case GrantTypeEnum.ClientCredentials:
                dict.Add("grant_type", "client_credentials");
                break;

            case GrantTypeEnum.AccountPassword:
                dict.Add("grant_type", "password");
                dict.Add("userName", account);
                dict.Add("passWord", pwd);
                break;

            default:
                return(Json(new { Success = false, Data = LanguageUtil.Translate("api_Controller_Oauth_GetTokenAsync_Data") }));
            }
            var data = await(@"http://" + Request.RequestUri.Authority + @"/token").PostUrlEncodedAsync(dict).ReceiveJson <Token>();

            return(Json(new { Success = true, Data = data }));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GrantRequestPassword" /> class.
 /// </summary>
 /// <param name="grantType">The type of access token you are requesting. (required) (default to GrantTypeEnum.Password).</param>
 /// <param name="username">Your user name that you use to login to our site. (required).</param>
 /// <param name="password">Your user password that you use to login to our site. (required).</param>
 public GrantRequestPassword(GrantTypeEnum grantType = GrantTypeEnum.Password, string username = default(string), string password = default(string))
 {
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for GrantRequestPassword and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     // to ensure "username" is required (not null)
     if (username == null)
     {
         throw new InvalidDataException("username is a required property for GrantRequestPassword and cannot be null");
     }
     else
     {
         this.Username = username;
     }
     // to ensure "password" is required (not null)
     if (password == null)
     {
         throw new InvalidDataException("password is a required property for GrantRequestPassword and cannot be null");
     }
     else
     {
         this.Password = password;
     }
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TokenRequest" /> class.
 /// </summary>
 /// <param name="ClientId">ClientId (required).</param>
 /// <param name="ClientSecret">ClientSecret (required).</param>
 /// <param name="GrantType">GrantType (required).</param>
 /// <param name="Username">Username.</param>
 /// <param name="Password">Password.</param>
 /// <param name="Scopes">Scopes.</param>
 /// <param name="RefreshToken">RefreshToken.</param>
 /// <param name="ClientVersion">ClientVersion.</param>
 public TokenRequest(string ClientId = default(string), string ClientSecret = default(string), GrantTypeEnum GrantType = default(GrantTypeEnum), string Username = default(string), string Password = default(string), List <string> Scopes = default(List <string>), string RefreshToken = default(string), string ClientVersion = default(string))
 {
     // to ensure "ClientId" is required (not null)
     if (ClientId == null)
     {
         throw new InvalidDataException("ClientId is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.ClientId = ClientId;
     }
     // to ensure "ClientSecret" is required (not null)
     if (ClientSecret == null)
     {
         throw new InvalidDataException("ClientSecret is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.ClientSecret = ClientSecret;
     }
     // to ensure "GrantType" is required (not null)
     if (GrantType == null)
     {
         throw new InvalidDataException("GrantType is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.GrantType = GrantType;
     }
     this.Username      = Username;
     this.Password      = Password;
     this.Scopes        = Scopes;
     this.RefreshToken  = RefreshToken;
     this.ClientVersion = ClientVersion;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrantRequestMeeting" /> class.
 /// </summary>
 /// <param name="grantType">The type of access token you are requesting. (required) (default to GrantTypeEnum.Meetingpasscode).</param>
 /// <param name="meetingNumericId">Meeting ID (required).</param>
 /// <param name="meetingPasscode">Pin (required).</param>
 public GrantRequestMeeting(GrantTypeEnum grantType = GrantTypeEnum.Meetingpasscode, string meetingNumericId = default(string), string meetingPasscode = default(string))
 {
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for GrantRequestMeeting and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     // to ensure "meetingNumericId" is required (not null)
     if (meetingNumericId == null)
     {
         throw new InvalidDataException("meetingNumericId is a required property for GrantRequestMeeting and cannot be null");
     }
     else
     {
         this.MeetingNumericId = meetingNumericId;
     }
     // to ensure "meetingPasscode" is required (not null)
     if (meetingPasscode == null)
     {
         throw new InvalidDataException("meetingPasscode is a required property for GrantRequestMeeting and cannot be null");
     }
     else
     {
         this.MeetingPasscode = meetingPasscode;
     }
 }
Пример #6
0
        public OAuth2RefreshToken(
            string clientId,
            string clientSecret,
            string refreshToken)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentNullException(nameof(clientSecret));
            }

            if (string.IsNullOrEmpty(refreshToken))
            {
                throw new ArgumentNullException(nameof(refreshToken));
            }

            _clientId     = clientId;
            _clientSecret = clientSecret;
            _refreshToken = refreshToken;
            _grantType    = GrantTypeEnum.RefreshToken;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GrantRequestClient" /> class.
 /// </summary>
 /// <param name="grantType">The type of access token you are requesting. (required) (default to GrantTypeEnum.Clientcredentials).</param>
 /// <param name="clientId">The value given within the BlueJeans Enterprise Administration console. (required).</param>
 /// <param name="clientSecret">The value given within the BlueJeans Enterprise Administration console. (required).</param>
 public GrantRequestClient(GrantTypeEnum grantType = GrantTypeEnum.Clientcredentials, string clientId = default(string), string clientSecret = default(string))
 {
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for GrantRequestClient and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     // to ensure "clientId" is required (not null)
     if (clientId == null)
     {
         throw new InvalidDataException("clientId is a required property for GrantRequestClient and cannot be null");
     }
     else
     {
         this.ClientId = clientId;
     }
     // to ensure "clientSecret" is required (not null)
     if (clientSecret == null)
     {
         throw new InvalidDataException("clientSecret is a required property for GrantRequestClient and cannot be null");
     }
     else
     {
         this.ClientSecret = clientSecret;
     }
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TokenRequest" /> class.
 /// </summary>
 /// <param name="clientId">Gets or Sets ClientId (required).</param>
 /// <param name="clientSecret">Gets or Sets ClientSecret (required).</param>
 /// <param name="grantType">Gets or Sets Grant_Type (required).</param>
 /// <param name="username">Gets or Sets Username.</param>
 /// <param name="password">Gets or Sets Password.</param>
 /// <param name="scopes">Gets or Sets Scopes.</param>
 /// <param name="refreshToken">Gets or Sets Refresh_Token.</param>
 /// <param name="clientVersion">Gets or Sets Client_Version.</param>
 public TokenRequest(string clientId = default(string), string clientSecret = default(string), GrantTypeEnum grantType = default(GrantTypeEnum), string username = default(string), string password = default(string), List <string> scopes = default(List <string>), string refreshToken = default(string), string clientVersion = default(string))
 {
     // to ensure "clientId" is required (not null)
     if (clientId == null)
     {
         throw new InvalidDataException("clientId is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.ClientId = clientId;
     }
     // to ensure "clientSecret" is required (not null)
     if (clientSecret == null)
     {
         throw new InvalidDataException("clientSecret is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.ClientSecret = clientSecret;
     }
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for TokenRequest and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     this.Username      = username;
     this.Password      = password;
     this.Scopes        = scopes;
     this.RefreshToken  = refreshToken;
     this.ClientVersion = clientVersion;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InlineObject29" /> class.
 /// </summary>
 /// <param name="grantType">The grant type. The value of this field must be &#x60;vimeo_oauth1&#x60;. (required).</param>
 /// <param name="token">The OAuth 1 token. (required).</param>
 /// <param name="tokenSecret">The OAuth 1 token secret. (required).</param>
 public InlineObject29(GrantTypeEnum grantType = default(GrantTypeEnum), string token = default(string), string tokenSecret = default(string))
 {
     this.GrantType = grantType;
     // to ensure "token" is required (not null)
     this.Token = token ?? throw new ArgumentNullException("token is a required property for InlineObject29 and cannot be null");
     // to ensure "tokenSecret" is required (not null)
     this.TokenSecret = tokenSecret ?? throw new ArgumentNullException("tokenSecret is a required property for InlineObject29 and cannot be null");
 }
Пример #10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RefreshTokenRequest" /> class.
        /// </summary>
        /// <param name="grantType">grantType (required).</param>
        /// <param name="refreshToken">
        ///     A refresh token that may be used to request new access tokens. Refresh tokens remain valid
        ///     for a maximum of 90 days. (required).
        /// </param>
        /// <param name="scope">
        ///     A space delimited set of requested permissions. The requested permissions can be narrower but not
        ///     broader than the permissions agreed during application registration. If this parameter is omitted, the permissions
        ///     agreed during application registration are used in place..
        /// </param>
        public RefreshTokenRequest(GrantTypeEnum grantType = default, string refreshToken = default, string scope = default)
        {
            this.GrantType    = grantType;
            this.RefreshToken =
                refreshToken ?? throw new InvalidDataException("refreshToken is a required property for RefreshTokenRequest and cannot be null");

            this.Scope = scope;
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InlineObject27" /> class.
 /// </summary>
 /// <param name="code">The authorization code received from the authorization server. (required).</param>
 /// <param name="grantType">The grant type. The value of this field must be &#x60;authorization_code&#x60;. (required).</param>
 /// <param name="redirectUri">The redirect URI. The value of this field must match the URI from &#x60;/oauth/authorize&#x60;. (required).</param>
 public InlineObject27(string code = default(string), GrantTypeEnum grantType = default(GrantTypeEnum), string redirectUri = default(string))
 {
     // to ensure "code" is required (not null)
     this.Code      = code ?? throw new ArgumentNullException("code is a required property for InlineObject27 and cannot be null");
     this.GrantType = grantType;
     // to ensure "redirectUri" is required (not null)
     this.RedirectUri = redirectUri ?? throw new ArgumentNullException("redirectUri is a required property for InlineObject27 and cannot be null");
 }
Пример #12
0
        public async Task ExecuteAsync(HttpContext context)
        {
            // Request must be POST with Content-Type: application/x-www-form-urlencoded
            if (!context.Request.Method.Equals("POST") ||
                !context.Request.HasFormContentType)
            {
                await context.BadRequestAsync(new { error = "Bad request.." });

                return;
            }

            GrantTypeEnum grantType = GrantTypeEnum.password;

            try
            {
                grantType = (GrantTypeEnum)Enum.Parse(typeof(GrantTypeEnum), context.Request.Form["grant_type"], true);
            }
            catch
            {
                await context.BadRequestAsync(new { error = "invail grant_type" });

                return;
            }

            ClientResult clientResult = null;

            if (_options.ValidateClient && grantType != GrantTypeEnum.refresh_token)
            {
                clientResult = await VerifyClientAsync(context);

                if (!clientResult.Succeeded)
                {
                    await context.BadRequestAsync(clientResult.Error);

                    return;
                }
            }

            switch (grantType)
            {
            case GrantTypeEnum.password:
                await GenerateTokenByUserNamePassword(context, clientResult,
                                                      context.Request.Form["username"],
                                                      context.Request.Form["password"]);

                break;

            case GrantTypeEnum.refresh_token:
                await GenerateTokenByRefreshToken(context, context.Request.Form["refresh_token"]);

                break;
            }
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrantRequestCode" /> class.
 /// </summary>
 /// <param name="grantType">The type of access token you are requesting. Use \&quot;authorization_code\&quot;. (required) (default to GrantTypeEnum.Authorizationcode).</param>
 /// <param name="clientId">The client ID will be generated on creation of the application. Normally, a 32 character hexadecimal numeric string. (required).</param>
 /// <param name="clientSecret">The client secret will be generated on creation of the application. Retain this value as it will only be revealed one time. If lost, you will need to regenerate. (required).</param>
 /// <param name="redirectUri">One of the registered url or sub-url of registered urls. (required).</param>
 /// <param name="code">Code obtained after /oauth2/authorize redirect. (required).</param>
 public GrantRequestCode(GrantTypeEnum grantType = GrantTypeEnum.Authorizationcode, string clientId = default(string), string clientSecret = default(string), string redirectUri = default(string), string code = default(string))
 {
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for GrantRequestCode and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     // to ensure "clientId" is required (not null)
     if (clientId == null)
     {
         throw new InvalidDataException("clientId is a required property for GrantRequestCode and cannot be null");
     }
     else
     {
         this.ClientId = clientId;
     }
     // to ensure "clientSecret" is required (not null)
     if (clientSecret == null)
     {
         throw new InvalidDataException("clientSecret is a required property for GrantRequestCode and cannot be null");
     }
     else
     {
         this.ClientSecret = clientSecret;
     }
     // to ensure "redirectUri" is required (not null)
     if (redirectUri == null)
     {
         throw new InvalidDataException("redirectUri is a required property for GrantRequestCode and cannot be null");
     }
     else
     {
         this.RedirectUri = redirectUri;
     }
     // to ensure "code" is required (not null)
     if (code == null)
     {
         throw new InvalidDataException("code is a required property for GrantRequestCode and cannot be null");
     }
     else
     {
         this.Code = code;
     }
 }
        public async Task Invoke(HttpContext context)
        {
            if (!context.Request.Path.Equals(_options.Path, StringComparison.Ordinal))
            {
                await _next(context);

                return;
            }

            if (!context.Request.Method.Equals("POST") || !context.Request.HasFormContentType)
            {
                await BadRequest(context, new { error = "Bad request.." });

                return;
            }

            GrantTypeEnum grantType = GrantTypeEnum.password;

            try
            {
                grantType = (GrantTypeEnum)Enum.Parse(typeof(GrantTypeEnum), context.Request.Form["grant_type"], true);
            }
            catch
            {
                await BadRequest(context, new { error = "invail grant_type" });

                return;
            }

            switch (grantType)
            {
            case GrantTypeEnum.password:
                await GenerateTokenByUserNamePassWord(context, context.Request.Form["username"],
                                                      context.Request.Form["password"]);

                break;

            case GrantTypeEnum.refresh_token:
                await GenerateTokenByRefreshToken(context, context.Request.Form["refresh_token"]);

                break;
            }
        }
Пример #15
0
        public OAuth2AccessToken(
            string clientId,
            string clientSecret,
            string redirectUrl,
            string code,
            string scope)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            //if (string.IsNullOrEmpty(clientSecret))
            //{
            //    throw new ArgumentNullException(nameof(clientSecret));
            //}

            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            if (string.IsNullOrEmpty(redirectUrl))
            {
                throw new ArgumentNullException(nameof(redirectUrl));
            }

            if (string.IsNullOrEmpty(code))
            {
                throw new ArgumentNullException(nameof(code));
            }

            _clientId     = clientId;
            _clientSecret = clientSecret;
            _redirectUrl  = redirectUrl;
            _code         = code;
            _scope        = scope;
            _grantType    = GrantTypeEnum.AuthCode;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GrantRequestRefresh" /> class.
 /// </summary>
 /// <param name="grantType">The type of access token you are requesting. (required) (default to GrantTypeEnum.Refreshtoken).</param>
 /// <param name="clientId">The client ID will be generated on creation of the application. Normally, a 32 character hexadecimal numeric string. (required).</param>
 /// <param name="clientSecret">The client secret will be generated on creation of the application. Retain this value as it will only be revealed one time. If lost, you will need to regenerate. (required).</param>
 /// <param name="refreshToken">Refresh token obtained after token authorization. (required).</param>
 public GrantRequestRefresh(GrantTypeEnum grantType = GrantTypeEnum.Refreshtoken, string clientId = default(string), string clientSecret = default(string), string refreshToken = default(string))
 {
     // to ensure "grantType" is required (not null)
     if (grantType == null)
     {
         throw new InvalidDataException("grantType is a required property for GrantRequestRefresh and cannot be null");
     }
     else
     {
         this.GrantType = grantType;
     }
     // to ensure "clientId" is required (not null)
     if (clientId == null)
     {
         throw new InvalidDataException("clientId is a required property for GrantRequestRefresh and cannot be null");
     }
     else
     {
         this.ClientId = clientId;
     }
     // to ensure "clientSecret" is required (not null)
     if (clientSecret == null)
     {
         throw new InvalidDataException("clientSecret is a required property for GrantRequestRefresh and cannot be null");
     }
     else
     {
         this.ClientSecret = clientSecret;
     }
     // to ensure "refreshToken" is required (not null)
     if (refreshToken == null)
     {
         throw new InvalidDataException("refreshToken is a required property for GrantRequestRefresh and cannot be null");
     }
     else
     {
         this.RefreshToken = refreshToken;
     }
 }
        public async Task Invoke(HttpContext context)
        {
            // If the request path doesn't match, skip
            if (!context.Request.Path.Equals(_options.Path, StringComparison.Ordinal))
            {
                await _next(context);

                return;
            }

            // Request must be POST with Content-Type: application/x-www-form-urlencoded
            if (!context.Request.Method.Equals("POST") ||
                !context.Request.HasFormContentType)
            {
                await BadRequest(context, new { error = "Bad request.." });

                return;
            }

            GrantTypeEnum grantType = GrantTypeEnum.password;

            try
            {
                grantType = (GrantTypeEnum)Enum.Parse(typeof(GrantTypeEnum), context.Request.Form["grant_type"], true);
            }
            catch
            {
                await BadRequest(context, new { error = "invail grant_type" });

                return;
            }


            string clientId = string.Empty;

            if (_options.VerifyClient)
            {
                var headers = context.Request.Headers;

                string secretKey = string.Empty;

                try
                {
                    if (!string.IsNullOrEmpty(headers["Authorization"]))
                    {
                        var array = headers["Authorization"].ToString().Split(' ');
                        secretKey = array[1];
                    }
                }
                catch
                {
                    await BadRequest(context, new { error = "Invalid client" });

                    return;
                }

                IServiceProvider serviceProvider = context.RequestServices;

                var clientService = (IJWTClientService)serviceProvider.GetService(typeof(IJWTClientService));

                clientId = await clientService.VerifyClientByClientIdAsync(secretKey);

                if (string.IsNullOrEmpty(clientId))
                {
                    await BadRequest(context, new { error = "Invalid client" });

                    return;
                }
            }

            switch (grantType)
            {
            case GrantTypeEnum.password:
                await GenerateTokenByUserNamePassWord(context, clientId,
                                                      context.Request.Form["username"],
                                                      context.Request.Form["password"]);

                break;

            case GrantTypeEnum.refresh_token:
                await GenerateTokenByRefreshToken(context, clientId,
                                                  context.Request.Form["refresh_token"]);

                break;
            }
        }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InlineObject28" /> class.
 /// </summary>
 /// <param name="grantType">The grant type. The value of this field must be &#x60;client_credentials&#x60;. (required).</param>
 /// <param name="scope">A space-separated list of the authentication scopes to access. The default is &#x60;public&#x60;. (required).</param>
 public InlineObject28(GrantTypeEnum grantType = default(GrantTypeEnum), string scope = default(string))
 {
     this.GrantType = grantType;
     // to ensure "scope" is required (not null)
     this.Scope = scope ?? throw new ArgumentNullException("scope is a required property for InlineObject28 and cannot be null");
 }