コード例 #1
0
        public async Task InvokeAsync(HttpContext context, IJwtSecurityTokenService iJwtSecurityTokenService)
        {
            var grantResourceOwnerCredentialsContext = GrantResourceOwnerCredentialsContext.Create(context);

            if (grantResourceOwnerCredentialsContext != null)
            {
                await jwtServerOptions.AuthorizationServerProvider.GrantClientCredentialsAsync(grantResourceOwnerCredentialsContext);

                if (grantResourceOwnerCredentialsContext.IsValidated)
                {
                    var token = iJwtSecurityTokenService.Create(grantResourceOwnerCredentialsContext, jwtServerOptions);
                    await WriteResponseAsync(context, JsonConvert.SerializeObject(token));
                }
                else
                {
                    await WriteResponseError(context, grantResourceOwnerCredentialsContext.Error);
                }
            }
        }
コード例 #2
0
        public async Task InvokeAsync(HttpContext context, IJwtSecurityTokenService iJwtSecurityTokenService)
        {
            var baseValidatingContext = default(BaseValidatingContext);
            var grantType             = this.GetGrantType(context);

            switch (grantType)
            {
            case Parameters.Password:
                baseValidatingContext = GrantResourceOwnerCredentialsContext.Create(context);
                if (baseValidatingContext != null)
                {
                    await jwtServerOptions.AuthorizationServerProvider.GrantClientCredentialsAsync
                        ((GrantResourceOwnerCredentialsContext)baseValidatingContext);
                }
                break;

            case Parameters.RefreshToken:
                baseValidatingContext = GrantRefreshTokenContext.Create(context);
                if (baseValidatingContext != null)
                {
                    await jwtServerOptions.AuthorizationServerProvider.GrantRefreshTokenAsync
                        ((GrantRefreshTokenContext)baseValidatingContext);
                }
                break;

            default:
                break;
            }

            if (baseValidatingContext != null)
            {
                if (baseValidatingContext.IsValidated)
                {
                    var token = await iJwtSecurityTokenService.CreateAsync(baseValidatingContext, jwtServerOptions);
                    await WriteResponseAsync(context, JsonConvert.SerializeObject(token));
                }
                else
                {
                    await WriteResponseError(context, baseValidatingContext.Error);
                }
            }
        }