예제 #1
0
        public async Task ByRefreshToken(OAuthProviderContext context)
        {
            ProtectedTicket protectedTicket = await GrantRefreshToken(context.RefreshToken);

            if (protectedTicket == null)
            {
                context.SetError("Invalid refresh token");
                return;
            }

            if (protectedTicket.clientid != context.ClientId)
            {
                context.SetError("Invalid client id");
                return;
            }

            ClaimsIdentity identity = await GetIdentity(protectedTicket.username, protectedTicket.clientid);

            if (identity == null)
            {
                context.SetError("User not found");
                return;
            }

            string encodedJwt = CreateJWT(identity);

            context.SetToken(encodedJwt, context.RefreshToken);
            return;
        }
예제 #2
0
        public async Task ByPassword(OAuthProviderContext context)
        {
            ClaimsIdentity identity = await GetIdentity(context.Username, context.ClientId, context.Password);

            if (identity == null)
            {
                context.SetError("User not found");
                return;
            }

            string encodedJwt    = CreateJWT(identity);
            string refresh_token = await CreateRefreshToken(context.ClientId, identity);

            if (refresh_token == null)
            {
                context.SetError("Error while create refresh token");
                return;
            }

            context.SetToken(encodedJwt, refresh_token);
            return;
        }