Serenity: Sample: Token Authentication Required for Exposing Service Endpoint to Mobile Apps

Created on 3 May 2016  Â·  13Comments  Â·  Source: serenity-is/Serenity

Hello Volkanceylan,

Can you guide me where to write authentication filter for token authentication which can work seamlessly with existing forms ( cookie) authentication in Serenity Application

Api layer should get accessed by Mobile (Android / iOS) using token authentication

Thanks,

Sameer

Most helpful comment

Hello @baliuzao @NikunjGadhiya07 @mjacoup
I have successfully implemented token authentication with Serenity

Option 1:

Using serenity as it is using Cookie Authentication, where we use CookieContainer class to store cookies after authentication is successful and passing same cookie in every subsequent request.

Option 2: Token Authentication

Implemented JWT Token Authentication with Serenity where I will be generating First Token by passing username and password and retrieving AuthToken from Service

Then passing this AuthToken in every subsequent request to get data / post data to serenity services.

Option 3: I have successfully implemented Identity Server 4 for Serenity with Existing cookie Authentication yet to implement token authentication with IdentityServer and Serenity.

I will post code for all above option soon, may write wiki section.

All 13 comments

Cookie auth is also a token authentication. I dont have a sample for this. Any MVC token auth filter you find in internet should work with Serenity as well.

Hello @samdubey, have you any solution for this question? I used serenity API in kotlin android(retrofit). using that API login successfully done. but, In another API for fetching data, I got Authorization is required for this request!.

@NikunjGadhiya07 I have successfully implemented Serenity in Android Application, I am using CookieContainer to store cookie which i am using to pass along with api request to access the data.

@NikunjGadhiya07 I have successfully implemented Serenity in Android Application, I am using CookieContainer to store cookie which i am using to pass along with api request to access the data.

Can you please share with us the android code used to consume serenity API !! and if you have to authenticate first for every single request ???

Hi guys,
Did you make it?

Hello @baliuzao @NikunjGadhiya07 @mjacoup
I have successfully implemented token authentication with Serenity

Option 1:

Using serenity as it is using Cookie Authentication, where we use CookieContainer class to store cookies after authentication is successful and passing same cookie in every subsequent request.

Option 2: Token Authentication

Implemented JWT Token Authentication with Serenity where I will be generating First Token by passing username and password and retrieving AuthToken from Service

Then passing this AuthToken in every subsequent request to get data / post data to serenity services.

Option 3: I have successfully implemented Identity Server 4 for Serenity with Existing cookie Authentication yet to implement token authentication with IdentityServer and Serenity.

I will post code for all above option soon, may write wiki section.

@samdubey thanks,When can I release the code?

Hello @baliuzao @NikunjGadhiya07 @mjacoup
I have successfully implemented token authentication with Serenity

Option 1:

Using serenity as it is using Cookie Authentication, where we use CookieContainer class to store cookies after authentication is successful and passing same cookie in every subsequent request.

Option 2: Token Authentication

Implemented JWT Token Authentication with Serenity where I will be generating First Token by passing username and password and retrieving AuthToken from Service

Then passing this AuthToken in every subsequent request to get data / post data to serenity services.

Option 3: I have successfully implemented Identity Server 4 for Serenity with Existing cookie Authentication yet to implement token authentication with IdentityServer and Serenity.

I will post code for all above option soon, may write wiki section.

Code For Option 1:
https://github.com/samdubey/SerenityApiAccessCookieAuthentication

Code For Option 2:
https://github.com/samdubey/SerenityApiAccessTokenAuthentication

Code for Option 3:
https://github.com/samdubey/Serenity-IdentityServer4-Integration
In Visual Studio Run Multiple Projects together:
runTogether

Find Options:
FindLink

@samdubey
I have tried with your solution https://github.com/samdubey/SerenityApiAccessTokenAuthentication
I have success got the token. But when I try to post another API with send token back, I always got Error Code with NotLoggedIn.
图片

Do you have any idea where I am wrong?

I also tried with your code, also got the same error.
图片

you must create another endpoint from existing CustomerEndPoint as below:
You need to add following and remove existing permissions from Serenity to make it work
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("Api/Services/Northwind/Customer/[action]")]
[ConnectionKey(typeof(MyRow))]
public class CustomerApiController : ServiceEndpoint
{

@samdubey really Thanks a lot for your help.
Replace the _ServiceAuthorize_ AuthroizationSchemes with _Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)_ has any influence on the authorization check?

It has no effect on Authorization, It works flawlessly
It only enables you to use Token Authentication for that service

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitHubOrim picture GitHubOrim  Â·  3Comments

Akarsh03 picture Akarsh03  Â·  3Comments

Amitloh picture Amitloh  Â·  3Comments

Pinellus picture Pinellus  Â·  3Comments

StefanTheiner picture StefanTheiner  Â·  3Comments