java生成访问令牌_生成个人访问令牌以调用Azure Web Api(OAuth)

我有一个ASP.NET Web API,我在Azure Active Directory下注册了一个新的应用程序 .

这就是ConfigureAuth在Web API的源代码中的方式 .

public void ConfigureAuth(IAppBuilder app)

{

// Configure the db context and user manager to use a single instance per request

app.CreatePerOwinContext(ApplicationDbContext.Create);

app.CreatePerOwinContext(ApplicationUserManager.Create);

// Enable the application to use a cookie to store information for the signed in user

// and to use a cookie to temporarily store information about a user logging in with a third party login provider

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Configure the application for OAuth based flow

OAuthOptions = new OAuthAuthorizationServerOptions

{

AllowInsecureHttp = false,

TokenEndpointPath = new PathString("/Token"),

AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),

Provider = new ApplicationOAuthProvider("self"),

AuthenticationType = "LocalBearer"

};

// Enable the application to use bearer tokens to authenticate users

app.UseOAuthBearerTokens(OAuthOptions);

}

另一方面,我有一个命令行应用程序,可以访问Web API并向它询问一些数据 .

从命令行我无法使用用户凭据登录(这是一项要求)所以我想生成一个可能在一两年内到期的个人访问令牌,并使用该个人访问令牌构建我的API调用 . 如果可能,那么我可以避免使用用户名/密码登录来生成令牌 .

这个场景有没有文档?如何为我的控制台应用程序生成个人访问令牌以连接到Azure中托管的Web API?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值