How do I authenticate when calling an abp.io application REST Endpoint?

Viewed 702

I have a .Net Core application built with ABP.IO using the basic CLI. It exposes a swagger interface for basic user management and login etc. I can call any of the [Authorize]'d these end points from javascript once logged in or via Swagger OK. However this must be using some sort of authentication technique.

If I want to call the endpoints from curl or from another application how do I authenticate and get an access_token etc.?

I can call the login methods but they just return success on successful login. Is there a way to get an auth token or something to be able to then make calls to end points that require authentication.

This seems like a very natural thing to do

2 Answers

If your application is built with angular version. Angular Home compenent have already imported OAuthService. You can call OAuthService.getAccessToken(), and may copy to clipboard etc.

// this is already in template
get hasLoggedIn(): boolean {
    return this.oAuthService.hasValidAccessToken();
}

// you can add this to read bearer access token
get token(): string {
    return this.oAuthService.getAccessToken();
}

If it helps anyone else, I couldn't get the token via OAuthService, but I did get it via TokenService.

I injected it into the constructor and then called getToken()

this.tokenService.getToken()
Related