Zhenghao-Liu / OAuth_demo

OAuthDemo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

  • redis存储
  1. unordered_map<account,string> appID
  2. unordered_map<appID,string> account
  3. [code:${string}]=appID+"_"+account+"_"+scope
  4. [token:${string}]=appID+"_"+account+"_"+scope
  5. [refresh:${string}]=appID+"_"+account+"_"+scope
  • 场景
  1. user_info修改,通过unordered_map<appID,string> account把所有[code:${string}][token:${string}][refresh:${string}]删除
  2. oauth_info修改,通过unordered_map<account,string> appID把所有[code:${string}][token:${string}][refresh:${string}]删除
  3. 请求授权码,验证accountpasswordappID,验证其他参数,如果原先appID[account]、account[appID]有值s_old,那么应该取旧值并删除[code:${s_old}][token:${s_old}][refresh:${s_old}],生成s1appID[account]=s1account[appID]=s1[code:${s1}]=appID+"_"+account+"_"+scope,返回是s1即code
  4. 请求令牌,验证appIDappSecretcode,验证其他参数,从[code:${s1}]=appID+"_"+account+"_"+scope拿到appIDaccount,删除[code:${s1}]=appID+"_"+account+"_"+scope,生成s2s3appID[account]=account[appID]=s2+s3[token:${s2}]=[refresh:${s3}]=appID+"_"+account+"_"+scope,返回s2tokens3refresh_token
  5. 刷新令牌,验证appIDrefresh_token,从[refresh:${refresh_token}]中获取appIDaccount,新生成ss2ss3appID[account]=account[appID]=ss2+ss3[token:${ss2}]=[refresh:${ss3}]=appID+"_"+account+"_"+scope,返回ss2tokenss3refresh_token
  6. 申请资源,验证appIDtoken,从[token:${string}]=appID+"_"+account+"_"+scope中拿scope,之后去对应的account中拿对应的scope
  7. s1哈希后成为code的key,s2+s3逆哈希后,s2哈希后成为token的key,s3哈希后成为refresh的key,存的都是哈希过后的值,返回给客户端的都是没有加密的值

About

OAuthDemo


Languages

Language:Go 91.1%Language:HTML 8.1%Language:Makefile 0.6%Language:Shell 0.2%