でデコードします。私のWeb Api 2.2 OWINベースのアプリケーションでは、手動でベアラトークンをデコードする必要がありますが、これを行う方法はわかりません。 これは、手動でパラメータとして渡されたトークンからのクレームをデコードして取得するにはどのようにパラメータとして手動でOAuthベアラトークンをC#
[RoutePrefix("api/EP")]
public class EPController : MasterController
{
[HttpGet]
[AllowAnonymous]
[Route("DC")]
public async Task<HttpResponseMessage> GetDC(string token)
{
//Get the claim identity from the token here
//Startup.OAuthServerOptions...
//..and other stuff
}
}
をベアラトークンを送る私のコントローライムで
public class Startup
{
public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; }
public static UnityContainer IoC;
public void Configuration(IAppBuilder app)
{
//Set Auth configuration
ConfigureOAuth(app);
....and other stuff
}
public void ConfigureOAuth(IAppBuilder app)
{
OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new AuthProvider(IoC.Resolve<IUserService>(), IoC.Resolve<IAppSettings>())
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
}
私startup.csのですか?
NOTE:私は、ヘッダーにトークンを送信し、[承認]を使用して、(ClaimsIdentity)User.Identityのなどすることができます知っているが、問題は、それがヘッダに提示していないときに、トークンを読み取る方法です。
ありがとう、ちょうど私が探していたもの! Awesome –
上記はうまくいくかもしれませんが。より簡単な解決策はhttps://long2know.com/2015/05/decrypting-owin-authentication-ticket/ –