示例#1
0
        public static async Task<TokenEndPoint> GetTokenEndProint
        (
            IOwinContext owinContext,
            OAuthOptions options,
            AuthorizationCodeStorage storage,
            RefreshTokenStorage refreshTokenStorage
        )
        {
            var request = new TokenRequest(owinContext);
            await request.LoadAsync();

            var context = new OAuthContext(options, request, owinContext);

            return new TokenEndPoint(context, storage, refreshTokenStorage);
        }
示例#2
0
        public static async Task<Flow> Get
        (
            IOwinContext owinContext,
            OAuthOptions options,
            AuthorizationCodeStorage authCodeStorage,
            RefreshTokenStorage refreshTokenStorage
        )
        {
            var request = new AuthenticationRequest(owinContext);
            await request.LoadAsync();

            var context = new OAuthContext(options, request, owinContext);

            switch (context.AuthenticationRequest.response_type?.Trim())
            {
                case "code": return new AuthorizationCodeFlow(context, authCodeStorage);
                case "id_token": return new ImplicitFlow(context);
                case "id_token token": return new ImplicitFlow(context);
                case "code id_token": return new HybridFlow(context);
                case "code token": return new HybridFlow(context);
                case "code id_token token": return new HybridFlow(context);
                default: return null;
            }
        }
        internal static Task Singout(this IOwinContext context, OAuthOptions options)
        {
            //Unauthorized(context, options);

            return Task.FromResult<int>(0);
        }
 public static bool IsLoginRequest(this IOwinContext context, OAuthOptions options)
 {
     return context.Request.Path.Equals(options.AuthorizationUri);
 }
        internal static void Unauthorized(this IOwinContext context, OAuthOptions options, UnauthorizedException ex)
        {
            context.Response.StatusCode = 403;
            context.Response.ReasonPhrase = "Forbidden";

            if (ex.prompt.Equals("login"))
            {
                var url = $"{options.AuthorizationUri.Value}{context.Request.QueryString}";
                context.Response.Redirect(url);
            }
            else if (ex.prompt.Equals("none"))
            {
                var state = GetState(context);
                var response = new AuthenticationErrorResponse(ex.error, ex.error_description, state);

                context.Response.ContentType = "application/json";
                context.Response.Write(response.Json());
            }
        }
 public static void UseCarcarahMiddleware(this IAppBuilder app, OAuthOptions config)
 {
     app.Use<CarcarahOAuth>(config);
 }
示例#7
0
 public OAuthContext(OAuthOptions options, TokenRequest request, IOwinContext context)
 {
     Options = options;
     TokenRequest = request;
     OwinConext = context;
 }
示例#8
0
 public OAuthContext(OAuthOptions options, AuthenticationRequest request, IOwinContext context)
 {
     Options = options;
     AuthenticationRequest = request;
     OwinConext = context;
 }