-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to set current credentials manually? #825
Comments
This exactly. I am using React Native which current has no support for using the Hosted UI through AppSync. I am using Expo and it's provided
This works exactly as I expect it to: my user is created and I am given the access token for my cognito user. Now I would love to be able to supply this token to Amplify's Auth class to let it know that I have indeed authenticated my user. Without hacking up the library on my own, is it possible to do this? This is a blocker for our app to be able to continue (we do NOT want to federate Facebook login through a Cognito Identity Pool, but rather through the User Pool). |
@jdeanwaite Bit off topic: Does the authorize endpoint / custom UI support the native facebook app for login? Or will you get redirected to the web version of facebook and have to supply credentials? |
+1 |
Anyone got a solution to this? I was trying the same thing. |
Switch to firebase auth, step up OpenID with AWS cognito identity pools and aws appsync. Took me 30 minutes vs weeks of this.
…Sent from my iPhone
On Aug 5, 2018, at 8:17 AM, Leonardo Rodriguez ***@***.***> wrote:
Anyone got a solution to this? I was trying the same thing.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I wish I don’t have to move from AWS stack right now.
If no solution yet I will have to workaround using Identity Pool for now.
… On Aug 5, 2018, at 1:21 PM, Justin Waite ***@***.***> wrote:
Switch to firebase auth, step up OpenID with AWS cognito identity pools and aws appsync. Took me 30 minutes vs weeks of this.
Sent from my iPhone
> On Aug 5, 2018, at 8:17 AM, Leonardo Rodriguez ***@***.***> wrote:
>
> Anyone got a solution to this? I was trying the same thing.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I totally get it. I put up with it from January until July, then decided to move authentication to Firebase Auth. However, I do absolutely everything else through AWS, since Cognito Identity Pools has good integration with OpenID Connect, which firebase tokens are OpenID compatible.
… On Aug 5, 2018, at 3:19 PM, Leonardo Rodriguez ***@***.***> wrote:
I wish I don’t have to move from AWS stack right now.
If no solution yet I will have to workaround using Identity Pool for now.
> On Aug 5, 2018, at 1:21 PM, Justin Waite ***@***.***> wrote:
>
> Switch to firebase auth, step up OpenID with AWS cognito identity pools and aws appsync. Took me 30 minutes vs weeks of this.
>
> Sent from my iPhone
>
> > On Aug 5, 2018, at 8:17 AM, Leonardo Rodriguez ***@***.***> wrote:
> >
> > Anyone got a solution to this? I was trying the same thing.
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub, or mute the thread.
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#825 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AIH378td8LZM5KQbHwUs8qv7fSd-Q-2wks5uN2-KgaJpZM4T7ll6>.
|
@lcrodriguez I did end up finding a solution for this, at least for my particular use case. What you do is, set the jwt to something else in local storage. Then, when adding the Authorization header to an API call, you can pass in the jwt stored in localStorage Additionally, in all the functions in which you get a user's profile info, etc., you would need to check and see if your custom jwt is stored in localStorage; if it is, decode it yourself and then set the appropriate attributes you want. Code I used for API endpoint:
Code I used for getting a user's attributes; it's essentially overriding
|
Thanks much! I will give it a try in a few days and get back to you. |
@Guitarkalle about this feature request if I am understanding correctly, you want to pass the tokens(idToken, accessToken) to the Auth module manually, for example: let { idToken, accessToken, refreshToken, user } = somewhere();
Auth.setCognitoSession({
idToken,
accessToken,
refreshToken,
user
}).then(user => {
console.log(user); // The Cognito user object
});
// After doing that, you will create a cognito session for you. Amplify library will store this session into
// cache and return a Cognito user for you. An Aws credentials will also be loaded into library if you have
// configured your Cognito Federated Idnetity Pool |
@powerful23 exactly. |
@powerful23 exactly as you mentioned
but the problem is that we receive only id_Token, access_token and expires_in in the response URL?!! |
@engharb well that user could be optional. If not set, we can try to extract the user name from the jwt token. |
@powerful23 I mean that: |
@engharb yes it's still in implementation. The refreshToken will be optional in that session object. We are trying to make it as generic as possible to handle different cases. |
@powerful23 Any updates on this? |
@jannikweichert still working on it. |
I have followed #1143 and using amazon-cognito-auth-js to SignUp/SignIn using Social Accounts i.e FB, Google providers. |
@powerful23 I definitely need this.
|
I am looking for something same.
I want to create user Pool to make local login,like we have in aws-amplify |
@indrsidhu,
|
@powerful23 Do you have already the new Implementation or features for Social Login in User-Pool (Amplify-js)? Currently I am able to login to user-pool using i.e FB/Google account (in my Website) and using 'amazon-cognito-auth'. Then I can see the new record in User-Pool logged in users. (in my Mobile app) Is there any possibility to enable the user to login using new username created in user-pool with 'kind of' random generated password.? Of course the login doe not work for Mobile Application using the Amplify. |
@engharb Yes i see. I found a way to implement that and now it's working. |
If it can help someone, here is the example of code that i used. |
`import React from 'react'; const storage = new StorageHelper().getStorage(); const authData = { Auth.configure({ export const decodePayload = (jwtToken) => { export const calculateClockDrift = (iatAccessToken, iatIdToken) => { export class Login extends React.Component {
} const styles = StyleSheet.create({ |
Here is another example using Expo AuthSession `import React from 'react'; const storage = new StorageHelper().getStorage(); const authData = { Auth.configure({ export const decodePayload = (jwtToken) => { export const calculateClockDrift = (iatAccessToken, iatIdToken) => { export class Login extends React.Component {
} const styles = StyleSheet.create({ |
@tmjordan I would utilize aws-cognito-auth to store the tokens instead of doing that by myself
|
i tried that, but it didn't work for me |
@engharb you can get the redirect url which contains the tokens from the web browser, and then pass it to your method. |
@powerful23 @yuntuowang for simplicity I want to use Cordova-FB or GooglePlus plugins in order to login. And when I logged in successfully I want to pass the i.e FB:IAuthResponse->accessToken to aws oauth2 in order to log me in Cognito-UserPool and fetch the related tokens. Is that somehow possible?! Where for testing my mobile-app I can not use the webviews (embedded browsers known as “web-views”) in case of Google login. This is a restriction by Google itself "https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html". Is there a way for more digging in knowing the auth behavior betweet AWS-Auth-Server, Cgnito-UserPool, and Fb_provider? It would be helpful to know i.e the redirect urls... |
Hey could you please tell me how you did it? I've configured identity pool to use my firebase auth. In my app now how do i initialize Amplify Storage by passing the token from firebase to it? |
@powerful23 Please, how to use the new function to set session manually. I installed the beta version of amplify, but i can't find the new function. |
Hello everyone. We have been tracking this issue and working on solutions. The root use case seems to be making the OAuth flow easier, not only with React Native but in general. Setting the session manually appears to be an effect of the root problem. To this there are two things I wanted to update this issue and get some feedback on:
We're looking forward to your feedback and thank you for being patient while we work on this issue. |
Hello everyone, we have released the new HOC for React Native with the OAuth process of the Cognito Hosted UI (e.g. #1 above). Please see the instructions here: https://aws-amplify.github.io/docs/js/authentication#launching-the-hosted-ui-in-react-native |
@undefobj thanks for the update. However, I still need the functionality to set current credentials manually. I am storing my JWT in a cookie and sharing the token between multiple sites, so that is my use case. |
Hey, Is there anyway of tricking amplify into thinking it's authenticated with a token? i see that getCurrentSession() returns an object that contains the tokens, but no way to setCurrentSession()? I'm using amazon-cognito-identity-js in the lambda function, which is what amplify uses. I can even returned an authenticated CognitoUser object, but i see no way of setting it on the front end. |
@Xander567 here's what i did and it'w working perfectly for me until now. You just have to set the tokens manually, and amplify will just use them with no problems. You can login or logout and the tokens are refreshed automatically.
|
you can see the whole code in my previous comments |
Has this ever been released? I'm on react native and i need to login to my user pool via federatedSignIn (Google Provider). The problem is that every 1 hour the token expires and users are forced to login again through the hosted ui. I really need the ability to silently refresh the token and keep the user logged in. I'm trying to refresh the token myself like this
but i don't know how to set the "currentAuthenticatedUser" after that |
@powerful23 I also have this requirement for my project. It's an existing production app where I built my own authentication module with I don't see this PR in the current beta release: |
Is there any progress? |
Also wondering if there is any way to do this |
@powerful23 how are you? Thanks as always! |
Thank you so much @Xander567, this proved to be wonderful advice! Implementation detail for others in my case. I'm switching between multiple subdomains with the same authenticated user. For the authentication to work by coping the Cognito storage object (value in localstorage), I had to set bypassCache to true.
|
I've been experimenting with this myself, and
I will note that there is a great deal of reliance on the Credentials flow (especially with refreshing), so your implementation (e.g. In short, yes, it's possible, but there are more edge-cases to be worked around when working "off the rails". |
@ericclemmons what is the alternative to the approach you described? |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Is it possible to set the credentials for the current user manually in an easy way?
I have a custom login using the authorize and token endpoints (custom login interface), and wish to load the credentials in the Auth library to continue using it in the rest of my app.
The Auth lib has support for parsing a request from the hosted UI containing code and state parameters. It then makes a post to the TOKEN endpoint and loads the credentials. It doesn't seem to have support for PKCE sadly and it doesn't check the STATE parameter either I think to make sure it's correct? see getCodeQueryParameter in CognitoAuth.js for the parsing.
So I am wondering if it's possible to supply the JWT token to Auth for it to load the user etc.
I basically want to call CognitoAuth.onSuccessExchangeForToken
Is there an easy way to get access to the CognitoAuth instance in the Auth component (import { Auth } from 'aws-amplify';) so I can call its methods? One idea could be to expose a method for calling the /authorize endpoint yourself so you can initiate an authorization flow. As well as adding PKCE support for the flow. The rest of the functionality seems to be there already
The text was updated successfully, but these errors were encountered: